numpy logspace的用法


numpy.logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None)[source]

Return numbers spaced evenly on a log scale.

In linear space, the sequence starts at base ** start (base to the power of start) and ends with base ** stop (see endpoint below).


start : float

base ** start is the starting value of the sequence.

stop : float

base ** stop is the final value of the sequence, unless endpoint is False. In that case, num + 1 values are spaced over the interval in log-space, of which all but the last (a sequence of length num) are returned.

num : integer, optional

Number of samples to generate. Default is 50.

endpoint : boolean, optional

If true, stop is the last sample. Otherwise, it is not included. Default is True.

base : float, optional

The base of the log space. The step size between the elements in ln(samples) / ln(base) (or log_base(samples)) is uniform. Default is 10.0.

dtype : dtype

The type of the output array. If dtype is not given, infer the data type from the other input arguments.


samples : ndarray

num samples, equally spaced on a log scale


numpy.logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None)
比如 np.logspace(0,10,9)
array([1.00000000e+00, 1.77827941e+01, 3.16227766e+02, 5.62341325e+03,
1.00000000e+05, 1.77827941e+06, 3.16227766e+07, 5.62341325e+08,

第一位是开始值0,第二位是结束值10,然后在这0-10之间产生9个值,这9个值是均匀分布的,默认包括最后一个结束点,就是0到10的9个等产数列,那么根据等差数列的公式,a1+(n-1)*d=an,算出,d=1.25,那么a1=0,接着a2=1.25,a3=2.5,。。。。。a9=10,然后再对这9个值做已10为底的指数运算,也就是10^0, 10^1.25 , 10^2.5 这样的结果

0 个评论