📜  Python中的numpy.logspace

📅  最后修改于: 2020-06-05 00:50:44             🧑  作者: Mango

numpy.logspace(start, stop, num = 50, endpoint = True, base = 10.0, dtype = None) :返回对数刻度上间隔均匀的数字间隔。

 

参数:

-> start: [float]间隔范围的开始(基数**开始)。
-> stop:间隔范围的[float]结束(基数**停止)
-> endpoint: [布尔值,可选]如果为True,则停止是最后一个样本。默认情况下,True- 
> num: [int,可选]要生成的样本数
-> base: [float,可选]对数刻度的基数。默认情况下等于10.0- 
> dtype:输出数组的类型

返回:

ndarray

 

代码1:解释logspace()的用法

# Python编程说明numpy.logspace方法 
  
import numpy as geek 
  
# base = 11 
print("B\n", geek.logspace(2.0, 3.0, num=5, base = 11)) 
  
# base = 10 
print("B\n", geek.logspace(2.0, 3.0, num=5)) 
  
# base = 10, dtype = int 
print("B\n", geek.logspace(2.0, 3.0, num=5, dtype = int))

输出:

B 
 [121. 220.36039471 401.31159963 730.8527479 1331.] 
B 
 [100. 177.827941 316.22776602 562.34132519 1000.] 
B 
 [ 100177316316562 1000]

代码2:使用matplotlib模块– pylab的numpy.logspace()的图形表示

# numpy.logspace的图形表示
import numpy as geek 
import pylab as p 
  
# Start = 0 
# End = 2 
# Samples to generate = 10 
x1 = geek.logspace(0, 1, 10) 
y1 = geek.zeros(10) 
  
# Start = 0.1 
# End = 1.5 
# Samples to generate = 12 
x2 = geek.logspace(0.1, 1.5, 12) 
y2 = geek.zeros(12) 
  
p.plot(x1, y1+0.05, 'o') 
p.xlim(-0.2, 18) 
p.ylim(-0.5, 1) 
p.plot(x2, y2, 'x')

输出: