numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
Returns evenly spaced numbers within the specified interval.
Return num uniformly distributed samples, at [start, stop].
The endpoints of this interval can be arbitrarily excluded.
Parameters: |
start : scalar (scalar)
The starting value of the sequence.
stop : scalar
The end point of the sequence, unless endpoint is set to False, in which case, the sequence consists of all but the last of num + 1 evenly spaced samples (the sequence consists of all but the last of num + 1 evenly spaced samples ( I feel that this translation is a bit pitted)), so that stop is excluded. When endpoint is False, pay attention to the size of the step size (example below).
num : int, optional (optional)
The number of samples to generate, the default is 50. Must be non-negative.
endpoint : bool, optional
If true, stop must be included, if False, there must be no 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.
|
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 (only exists if retstep is set to true)
Only returned if retstep is True
Size of spacing between samples.
|
See also
-
arange
-
Similar to
linspace
, but uses a step size (instead of the number of samples).
-
arange uses the step size, not the number of samples
-
logspace
-
Samples uniformly distributed in log space.
When endpoint is set to False
>>> import numpy as np
>>> np.linspace(1, 10, 10)
array([ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.])
>>> np.linspace(1, 10, 10, endpoint = False)
array([ 1. , 1.9, 2.8, 3.7, 4.6, 5.5, 6.4, 7.3, 8.2, 9.1])
In [4]: np.linspace(1, 10, 10, endpoint = False, retstep= True)
Out[4]: (array([ 1. , 1.9, 2.8, 3.7, 4.6, 5.5, 6.4, 7.3, 8.2, 9.1]), 0.9)