numpy.linspace

Scipy.org -> Docs -> NumPy v1.15 Manual -> NumPy Reference -> Routines -> Array creation routines

numpy.linspace

numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)

Return evenly spaced numbers over a specified interval.
Returns num evenly spaced samples, calculated over the interval [start, stop].
The endpoint of the interval can optionally be excluded.
(即,返回指定區(qū)間[start,stop]內(nèi),均勻間隔的數(shù)值。num表示一共要獲得多少數(shù)字。endpoint表示所得數(shù)字是否包含端點(diǎn)stop,默認(rèn)包含。retstep表示是否給出數(shù)字之間的間隔值。dtype為數(shù)字的類型。)

Parameters:

  • start : scalar
    The starting value of the sequence.
  • stop : scalar
    The end value of the sequence, unless endpoint is set to False. In that case, the sequence consists of all but the last of num + 1 evenly spaced samples, so that stop is excluded. Note that the step size changes when endpoint is False.
  • num : int, optional
    Number of samples to generate. Default is 50. Must be non-negative.
  • endpoint : bool, optional
    If True, stop is the last sample. Otherwise, it is not included. Default is True.
  • retstep : bool, optional
    If True, return (samples, step), where step is the spacing between samples.(retstep為true的話,返回值中,除了給出一系列樣本點(diǎn)(samples),還會給出樣本點(diǎn)之間的間隔大小step。)
  • dtype : dtype, optional
    The type of the output array. If dtype is not given, infer the data type from the other input arguments.

New in version 1.9.0.

Returns:

  • samples : ndarray
    There are num equally spaced samples in the closed interval [start, stop] or the half-open interval [start, stop) (depending on whether endpoint is True or False).
  • step : float, optional
    Only returned if retstep is True
    Size of spacing between samples.

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) # 所選取的樣本點(diǎn)不包含右端點(diǎn)。
array([ 2. ,  2.2,  2.4,  2.6,  2.8])
>>> np.linspace(2.0, 3.0, num=5, retstep=True) # 每兩個樣本點(diǎn)之間間隔0.25。
(array([ 2.  ,  2.25,  2.5 ,  2.75,  3.  ]), 0.25)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,872評論 0 10
  • 如今,《王者榮耀》已儼然成為當(dāng)下年輕人中最流行的一款游戲,在閑暇之余很多人都想打上一把來消遣時光??晒P者在此款游戲...
    折口怪言閱讀 411評論 1 1
  • 歲月是無情的 不經(jīng)意間就溜走 歲月是有情的 給我們以成長、收獲 她永遠(yuǎn)是最杰出的的畫師 你懈怠、你勤奮 你背離、你...
    長安秋葉閱讀 223評論 0 0
  • 第一天,有人鼓勵、贊賞…… 第二天,有人不屑、嘲諷…… 第三天,………. 第十一天,有人說我裝逼,有人說我天天撒雞...
    小黃毛學(xué)長閱讀 377評論 0 0

友情鏈接更多精彩內(nèi)容