Help on function linspace in module numpy:
linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0)
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.
versionchanged:: 1.16.0
Non-scalar start
and stop
are now supported.
endpoint
is set to False.num + 1
stop
is excluded. Note that the stependpoint
is False.stop
is the last sample. Otherwise, it is not included.samples
, step
), where step
is the spacingdtype
is not given, infer the dataversionadded:: 1.9.0
versionadded:: 1.16.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.
See Also
--------
arange : Similar to linspace
, but uses a step size (instead of the
number of samples).
geomspace : Similar to linspace
, but with numbers spaced evenly on a log
scale (a geometric progression).
logspace : Similar to geomspace
, but with the end points specified as
logarithms.
>>> import numpy as np
>>> 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)
Graphical illustration:
import numpy as np
import matplotlib.pyplot as plt
N = 8
y = np.zeros(N)
x1 = np.linspace(0, 10, N, endpoint=True)
x2 = np.linspace(0, 10, N, endpoint=False)
plt.plot(x1, y, 'o')
plt.plot(x2, y + 0.5, 'o')
plt.ylim([-0.5, 1])
plt.show()