Python numpy.logspace
numpy.logspace 返回一组以对数刻度均匀间隔的数字。其语法如下所示:
numpy.logspace(start, stop, num = 50, endpoint = True/False, base = 10.0, dtype = None)
参数
logspace函数可以接受以下参数 –
- start - 序列的起始值;默认值为零。
-
stop - 序列的结束点。
-
num - 在起始值和结束点之间生成的元素数量。
-
endpoint - 控制是否将停止值包含在输出数组中。如果endpoint为真,则stop参数作为nd.array的最后一项包含在内。如果endpoint为false,则不包含stop参数。
-
base - logspace的底数。默认值为10.0。
-
dtype - 描述输出数组的类型。
示例1
让我们来看以下示例 –
# Import the required library
import numpy as np
# logspace() function
x = np.logspace(start = 1, stop = 8, endpoint = False)
print ("logspace of X : \n", x)
输出
上述程序将生成以下输出 –
logspace of X :
[1.00000000e+01 1.38038426e+01 1.90546072e+01 2.63026799e+01
3.63078055e+01 5.01187234e+01 6.91830971e+01 9.54992586e+01
1.31825674e+02 1.81970086e+02 2.51188643e+02 3.46736850e+02
4.78630092e+02 6.60693448e+02 9.12010839e+02 1.25892541e+03
1.73780083e+03 2.39883292e+03 3.31131121e+03 4.57088190e+03
6.30957344e+03 8.70963590e+03 1.20226443e+04 1.65958691e+04
2.29086765e+04 3.16227766e+04 4.36515832e+04 6.02559586e+04
8.31763771e+04 1.14815362e+05 1.58489319e+05 2.18776162e+05
3.01995172e+05 4.16869383e+05 5.75439937e+05 7.94328235e+05
1.09647820e+06 1.51356125e+06 2.08929613e+06 2.88403150e+06
3.98107171e+06 5.49540874e+06 7.58577575e+06 1.04712855e+07
1.44543977e+07 1.99526231e+07 2.75422870e+07 3.80189396e+07
5.24807460e+07 7.24435960e+07]
示例2
让我们来看另一个示例。考虑以下示例−
# Import numpy
import numpy as np
# logspace() function
x = np.logspace(start = 2, stop = 4, num = 4, base = 3.0)
print ("logspace of X :\n", x)
输出
它将生成以下输出 –
logspace of X :
[ 9. 18.72075441 38.9407384 81. ]
在这里,我们有 num=4 ,所以它只生成在起始和结束之间的4个元素。 并且我们将基数设置为3.0,而不是默认的10.0。