np.linespace用法
覺得有用的話,歡迎一起討論相互學習~




生成指定范圍內指定個數的一維數組
def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None):
- 在指定的間隔["start","stop"]內均勻地返回數字。返回“num”個等間距的樣本。
endpoint
是一個bool類型的值,如果為"Ture","stop"是最后一個值,如果為"False",生成的數組不會包含"stop"值
retstep
是一個bool類型的值,如果為"Ture",會返回樣本之間的間隙。
其他相似的函數
arange
和 linespace
相似,但是使用步長而不是樣本的數量來確定生成樣本的數量。
>>> 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)