在 NumPy 中使用複雜輸入返回幾何級數上均勻間隔的數字
要返回幾何級數上均勻間隔的數字,請在 Python NumPy 中使用 **numpy.geomspace()** 方法 -
- 第一個引數是“start”,即序列的開始
- 第二個引數是“end”,即序列的結束
- 第三個引數是 num,即要生成的樣本數。預設為 50。
我們設定了複雜輸入。
start 是序列的起始值。stop 是序列的最終值,除非 endpoint 為 False。在這種情況下,num + 1 個值在對數空間中間隔開,其中除了最後一個(長度為 num 的序列)之外的所有值都將被返回。如果 endpoint 為 True,則 stop 是最後一個樣本。否則,它不包括在內。預設為 True。
結果中儲存樣本的軸。僅當 start 或 stop 為陣列狀時才相關。預設情況下 (0),樣本將沿著插入到開頭的新的軸。使用 -1 在末尾獲取軸。
步驟
首先,匯入所需的庫 -
import numpy as np
返回幾何級數上均勻間隔的數字,使用 numpy.geomspace() 方法 -
arr = np.geomspace(10j, 100j, num = 5) print("Array...
", arr)
獲取型別 -
print("
Type...
", arr.dtype)
獲取維度 -
print("
Dimensions...
",arr.ndim)
獲取形狀 -
print("
Shape...
",arr.shape)
獲取元素數量 -
print("
Number of elements...
",arr.size)
示例
import numpy as np # To return evenly spaced numbers on a geometric progression, use the numpy.geomspace() method in Python Numpy # The 1st parameter is the "start" i.e. the start of the sequence # The 2nd parameter is the "end" i.e. the end of the sequence # The 3rd parameter is the num i.s the number of samples to generate. Default is 50. # We have set complex inputs arr = np.geomspace(10j, 100j, num = 5) print("Array...
", arr) # Get the type print("
Type...
", arr.dtype) # Get the dimensions print("
Dimensions...
",arr.ndim) # Get the shape print("
Shape...
",arr.shape) # Get the number of elements print("
Number of elements...
",arr.size)
輸出
Array... [0. +10.j 0. +17.7827941j 0. +31.6227766j 0. +56.23413252j 0.+100.j ] Type... complex128 Dimensions... 1 Shape... (5,) Number of elements... 5
廣告