numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
在指定的間隔內返回均勻間隔的數(shù)字婉刀。
返回num均勻分布的樣本,在[start, stop]。
這個區(qū)間的端點可以任意的被排除在外。
參數(shù)解釋:
start?: scalar(標量)
The starting value of the sequence(序列的起始點).
stop?: scalar
序列的結束點,除非endpoint被設置為False,在這種情況下, the sequence consists of all but the last of?num?+?1?evenly spaced samples(該序列包括所有除了最后的num+1上均勻分布的樣本(感覺這樣翻譯有點坑)), 以致于stop被排除.當endpoint?is False的時候注意步長的大小(下面有例子).
num?: int, optional(可選)
生成的樣本數(shù),默認是50史翘。必須是非負。
endpoint?: bool, optional
如果是真,則一定包括stop琼讽,如果為False必峰,一定不會有stop
retstep?: bool, optional
If True, return (samples,?step), where?step?is the spacing between samples.(看例子)
dtype?: dtype, optional
The type of the output array. If?dtype?is not given, infer the data type from the other input arguments(推斷這個輸入用例從其他的輸入中).
官網的例子
Examples
>>>
>>> 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)