在NumPy中返回对数刻度上的等间距数字
要在对数刻度上返回等间距的数字,请在Python NumPy中使用**numpy.logspace()**方法。第一个参数是“**start**”,即序列的起始值;第二个参数是“**end**”,即序列的结束值。
在线性空间中,序列从底数**start**(底数的start次方)开始,以底数**stop**(见下面的endpoint)结束。start是底数的start次方,是序列的起始值。stop是底数的stop次方,是序列的最终值,除非endpoint为False。在这种情况下,num+1个值在对数空间中均匀分布,除了最后一个值之外,所有值都会被返回。对数空间的底数。ln(samples)/ln(base) (或log_base(samples))中的元素之间的步长是均匀的。默认为10.0。
结果中存储样本的轴。仅当start或stop为数组时才相关。默认情况下(0),样本将沿着插入到开头的新的轴。使用-1在末尾获得一个轴。
步骤
首先,导入所需的库:
import numpy as np
使用Python NumPy中的numpy.logspace()方法返回对数刻度上的等间距数字。第三个参数num是要生成的样本数量。默认为50:
arr = np.logspace(35.0, 70.0) print("Array...
", arr)
获取类型:
print("
Type...
", arr.dtype)
获取维度:
print("
Dimensions...
",arr.ndim)
获取形状:
print("
Shape...
",arr.shape)
获取元素数量:
print("
Number of elements...
",arr.size)
示例
import numpy as np # To return evenly spaced numbers on a log scale, use the numpy.logspace() method in Python Numpy # The 1st parameter is the "start" i.e. the start of the sequence # The 2nd parameter is the "end" i.e. the end of the sequence # The 3rd parameter is the num i.s the number of samples to generate. Default is 50. arr = np.logspace(35.0, 70.0) print("Array...
", arr) # Get the type print("
Type...
", arr.dtype) # Get the dimensions print("
Dimensions...
",arr.ndim) # Get the shape print("
Shape...
",arr.shape) # Get the number of elements print("
Number of elements...
",arr.size)
输出
Array... [1.00000000e+35 5.17947468e+35 2.68269580e+36 1.38949549e+37 7.19685673e+37 3.72759372e+38 1.93069773e+39 1.00000000e+40 5.17947468e+40 2.68269580e+41 1.38949549e+42 7.19685673e+42 3.72759372e+43 1.93069773e+44 1.00000000e+45 5.17947468e+45 2.68269580e+46 1.38949549e+47 7.19685673e+47 3.72759372e+48 1.93069773e+49 1.00000000e+50 5.17947468e+50 2.68269580e+51 1.38949549e+52 7.19685673e+52 3.72759372e+53 1.93069773e+54 1.00000000e+55 5.17947468e+55 2.68269580e+56 1.38949549e+57 7.19685673e+57 3.72759372e+58 1.93069773e+59 1.00000000e+60 5.17947468e+60 2.68269580e+61 1.38949549e+62 7.19685673e+62 3.72759372e+63 1.93069773e+64 1.00000000e+65 5.17947468e+65 2.68269580e+66 1.38949549e+67 7.19685673e+67 3.72759372e+68 1.93069773e+69 1.00000000e+70] Type... float64 Dimensions... 1 Shape... (50,) Number of elements... 50
广告