在NumPy中返回對數刻度上的等間距數字
要在對數刻度上返回等間距的數字,請在Python NumPy中使用**numpy.logspace()**方法。第一個引數是“**start**”,即序列的起始值;第二個引數是“**end**”,即序列的結束值。
線上性空間中,序列從底數**start**(底數的start次方)開始,以底數**stop**(見下面的endpoint)結束。start是底數的start次方,是序列的起始值。stop是底數的stop次方,是序列的最終值,除非endpoint為False。在這種情況下,num+1個值在對數空間中均勻分佈,除了最後一個值之外,所有值都會被返回。對數空間的底數。ln(samples)/ln(base) (或log_base(samples))中的元素之間的步長是均勻的。預設為10.0。
結果中儲存樣本的軸。僅當start或stop為陣列時才相關。預設情況下(0),樣本將沿著插入到開頭的新的軸。使用-1在末尾獲得一個軸。
步驟
首先,匯入所需的庫:
import numpy as np
使用Python NumPy中的numpy.logspace()方法返回對數刻度上的等間距數字。第三個引數num是要生成的樣本數量。預設為50:
arr = np.logspace(35.0, 70.0)
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.s the number of samples to generate. Default is 50.
arr = np.logspace(35.0, 70.0)
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... [1.00000000e+35 5.17947468e+35 2.68269580e+36 1.38949549e+37 7.19685673e+37 3.72759372e+38 1.93069773e+39 1.00000000e+40 5.17947468e+40 2.68269580e+41 1.38949549e+42 7.19685673e+42 3.72759372e+43 1.93069773e+44 1.00000000e+45 5.17947468e+45 2.68269580e+46 1.38949549e+47 7.19685673e+47 3.72759372e+48 1.93069773e+49 1.00000000e+50 5.17947468e+50 2.68269580e+51 1.38949549e+52 7.19685673e+52 3.72759372e+53 1.93069773e+54 1.00000000e+55 5.17947468e+55 2.68269580e+56 1.38949549e+57 7.19685673e+57 3.72759372e+58 1.93069773e+59 1.00000000e+60 5.17947468e+60 2.68269580e+61 1.38949549e+62 7.19685673e+62 3.72759372e+63 1.93069773e+64 1.00000000e+65 5.17947468e+65 2.68269580e+66 1.38949549e+67 7.19685673e+67 3.72759372e+68 1.93069773e+69 1.00000000e+70] Type... float64 Dimensions... 1 Shape... (50,) Number of elements... 50
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP