📜  Python中的 numpy.geomspace()

📅  最后修改于: 2022-05-13 01:54:39.500000             🧑  作者: Mango

Python中的 numpy.geomspace()

numpy.geomspace()用于返回在对数尺度上均匀分布的数字(几何级数)。
这类似于 numpy.logspace() 但直接指定端点。每个输出样本都是前一个的常数倍。

代码#1:工作

Python
# Python3 Program demonstrate
# numpy.geomspace() function
 
import numpy as geek
 
 
print("B\n", geek.geomspace(2.0, 3.0, num = 5), "\n")
 
# To evaluate sin() in long range
point = geek.geomspace(1, 2, 10)
print("A\n", geek.sin(point))


Python
# Graphical Representation of numpy.geomspace()
import numpy as geek
import pylab as p
% matplotlib inline 
 
# Start = 1
# End = 3
 
# Samples to generate = 10
x1 = geek.geomspace(1, 3, 10, endpoint = False)
y1 = geek.ones(10)
   
p.plot(x1, y1, '+')


输出 :

B
 [ 2.          2.21336384  2.44948974  2.71080601  3.        ] 

A
 [ 0.84147098  0.88198596  0.91939085  0.95206619  0.9780296   0.9948976
  0.99986214  0.98969411  0.96079161  0.90929743]


代码 #2:numpy.geomspace() 的图形表示

Python

# Graphical Representation of numpy.geomspace()
import numpy as geek
import pylab as p
% matplotlib inline 
 
# Start = 1
# End = 3
 
# Samples to generate = 10
x1 = geek.geomspace(1, 3, 10, endpoint = False)
y1 = geek.ones(10)
   
p.plot(x1, y1, '+')

输出 :