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)