numpy.geomspace()
用於返回以對數刻度(幾何級數)均勻間隔的數字。
這類似於numpy.logspace()
但直接指定端點。每個輸出樣本是前一個樣本的恒定倍數。
用法: numpy.geomspace(start, stop, num=50, endpoint=True, dtype=None)
參數:
start :[scalar]序列的起始值。
stop :[scalar]序列的最終值,除非端點為False。在這種情況下,num + 1值在log-space中的時間間隔內間隔開,返回除最後一個(長度為num的序列)以外的所有值。
num :[整數,可選]要生成的樣本數。默認值為50。
endpoint:[布爾值,可選]如果為true,則stop是最後一個樣本。否則,不包括在內。默認值為True。
dtype :[dtype]輸出數組的類型。如果未給出dtype,則從其他輸入參數推斷數據類型。
Return :
samples:[ndarray] num個樣本,在對數刻度上等距分布。
代碼1:工作
# 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))
輸出:
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()的圖形表示
# Graphical Represenation 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, '+')
輸出:
相關用法
注:本文由純淨天空篩選整理自jana_sayantan大神的英文原創作品 numpy.geomspace() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。