【Python】np.linspace用法介紹

np.linspace主要用來創建等差數列。
np.linspace參數:

numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0)
Return evenly spaced numbers over a specified interval.
(在start和stop之間返回均勻間隔的數據)
Returns num evenly spaced samples, calculated over the interval [start, stop].
(返回的是 [start, stop]之間的均勻分佈)
The endpoint of the interval can optionally be excluded.
Changed in version 1.16.0: Non-scalar start and stop are now supported.
(可以選擇是否排除間隔的終點)

參數含義:

start:返回樣本數據開始點
stop:返回樣本數據結束點
num:生成的樣本數據量,默認爲50
endpoint:True則包含stop;False則不包含stop
retstep:If True, return (samples, step), where step is the spacing between samples.(即如果爲True則結果會給出數據間隔)
dtype:輸出數組類型
axis:0(默認)或-1

使用例子:

>>> np.linspace(2.0, 3.0, num=5)
array([ 2.  ,  2.25,  2.5 ,  2.75,  3.  ])
>>> np.linspace(2.0, 3.0, num=5, endpoint=False)
array([ 2. ,  2.2,  2.4,  2.6,  2.8])
>>> np.linspace(2.0, 3.0, num=5, retstep=True)
(array([ 2.  ,  2.25,  2.5 ,  2.75,  3.  ]), 0.25)

我們下次再見,如果還有下次的話!!!
歡迎關注微信公衆號:516數據工作室
516數據工作室

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章