当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python numpy.logspace()用法及代码示例


关于:
numpy.logspace(开始,停止,num = 50,端点= True,基数= 10.0,dtype =无):以对数刻度平均间隔间隔返回数字间隔。
参数:

-> start    : [float] start(base ** start) of interval range.
-> stop     : [float] end(base ** stop) of interval range
-> endpoint : [boolean, optional]If True, stop is the last sample. By default, True
-> num      : [int, optional] No. of samples to generate
-> base     : [float, optional] Base of log scale. By default, equals 10.0
-> dtype    : type of output array

返回:

-> ndarray


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


# Python Programming illustrating 
# numpy.logspace method 
  
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
 [ 100  177  316  562 1000]

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

# Graphical Represenation of 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')

输出:

注意:
这些NumPy-Python程序不会在onlineID上运行,因此请在您的系统上运行它们以进行探索

相似方法:

相关用法


注:本文由纯净天空筛选整理自 numpy.logspace() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。