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.
(即,返回指定区间[start,stop]内,均匀间隔的数值。num表示一共要获得多少数字。endpoint表示所得数字是否包含端点stop,默认包含。retstep表示是否给出数字之间的间隔值。dtype为数字的类型。)
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的话,返回值中,除了给出一系列样本点(samples),还会给出样本点之间的间隔大小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) # 所选取的样本点不包含右端点。
array([ 2. , 2.2, 2.4, 2.6, 2.8])
>>> np.linspace(2.0, 3.0, num=5, retstep=True) # 每两个样本点之间间隔0.25。
(array([ 2. , 2.25, 2.5 , 2.75, 3. ]), 0.25)