在 Numpy 中返回對數刻度上的等間距數字,並且不設定端點
要返回對數刻度上的等間距數字,請在 Python Numpy 中使用 numpy.logspace() 方法。第一個引數是“start”,即序列的開始。第二個引數是“end”,即序列的結束。第三個引數是“num”,即要生成的樣本數。預設為 50。第四個引數是“endpoint”。如果為 True,則 stop 是最後一個樣本。否則,它不包含在內。預設為 True。
線上性空間中,序列從 base ** start(底數的 start 次冪)開始,以 base ** stop(參見下面的 endpoint)結束。start 是 base ** start 是序列的起始值。stop 是 base ** stop 是序列的最終值,除非 endpoint 為 False。在這種情況下,num + 1 個值在對數空間中的區間內等距分佈,其中除了最後一個值之外的所有值都將被返回。對數空間的底數。ln(samples) / ln(base)(或 log_base(samples))中的元素之間的步長是統一的。預設為 10.0。
結果中儲存樣本的軸。僅當 start 或 stop 為陣列狀時才相關。預設情況下(0),樣本將沿著插入到開頭的新軸。使用 -1 獲取末尾的軸。
步驟
首先,匯入所需的庫 -
import numpy as np
要返回對數刻度上的等間距數字,請使用 numpy.logspace() 方法 -
arr = np.logspace(100.5, 200.7, num = 10, endpoint = False)
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 log scale, use the numpy.logspace() 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.e the number of samples to generate. Default is 50.
# The 4th parameter is the "endpoint". If True, stop is the last sample. Otherwise, it is not included. Default is True.
arr = np.logspace(100.5, 200.7, num = 10, endpoint = False)
print("Array...
", arr)
# Get the array type
print("
Type...
", arr.dtype)
# Get the dimensions of the Array
print("
Dimensions...
",arr.ndim)
# Get the shape of the Array
print("
Shape...
",arr.shape)
# Get the number of elements
print("
Number of elements...
",arr.size)輸出
Array... [3.16227766e+100 3.31131121e+110 3.46736850e+120 3.63078055e+130 3.80189396e+140 3.98107171e+150 4.16869383e+160 4.36515832e+170 4.57088190e+180 4.78630092e+190] Type... float64 Dimensions... 1 Shape... (10,) Number of elements... 10
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP