linspace¶
- linspace(start: int | float | complex, stop: int | float | complex, /, num: int, *, dtype: dtype | None = None, device: device | None = None, endpoint: bool = True) array ¶
Returns evenly spaced numbers over a specified interval.
Let \(N\) be the number of generated values (which is either
num
ornum+1
depending on whetherendpoint
isTrue
orFalse
, respectively). For real-valued output arrays, the spacing between values is given by\[\Delta_{\textrm{real}} = \frac{\textrm{stop} - \textrm{start}}{N - 1}\]For complex output arrays, let
a = real(start)
,b = imag(start)
,c = real(stop)
, andd = imag(stop)
. The spacing between complex values is given by\[\Delta_{\textrm{complex}} = \frac{c-a}{N-1} + \frac{d-b}{N-1} j\]- Parameters:
start (Union[int, float, complex]) – the start of the interval.
stop (Union[int, float, complex]) –
the end of the interval. If
endpoint
isFalse
, the function must generate a sequence ofnum+1
evenly spaced numbers starting withstart
and ending withstop
and exclude thestop
from the returned array such that the returned array consists of evenly spaced numbers over the half-open interval[start, stop)
. Ifendpoint
isTrue
, the output array must consist of evenly spaced numbers over the closed interval[start, stop]
. Default:True
.Note
The step size changes when
endpoint
isFalse
.num (int) – number of samples. Must be a nonnegative integer value.
dtype (Optional[dtype]) –
output array data type. Should be a floating-point data type. If
dtype
isNone
,if either
start
orstop
is acomplex
number, the output data type must be the default complex floating-point data type.if both
start
andstop
are real-valued, the output data type must be the default real-valued floating-point data type.
Default:
None
.Note
If
dtype
is notNone
, conversion ofstart
andstop
should obey Type Promotion Rules rules. Conversions not specified according to Type Promotion Rules rules may or may not be permitted by a conforming array library.device (Optional[device]) – device on which to place the created array. Default:
None
.endpoint (bool) – boolean indicating whether to include
stop
in the interval. Default:True
.
- Returns:
out (array) – a one-dimensional array containing evenly spaced values.
Notes
Note
While this specification recommends that this function only return arrays having a floating-point data type, specification-compliant array libraries may choose to support output arrays having an integer data type (e.g., due to backward compatibility concerns). However, function behavior when generating integer output arrays is unspecified and, thus, is implementation-defined. Accordingly, using this function to generate integer output arrays is not portable.
Note
As mixed data type promotion is implementation-defined, behavior when
start
orstop
exceeds the maximum safe integer of an output floating-point data type is implementation-defined. An implementation may choose to overflow or raise an exception.Changed in version 2022.12: Added complex data type support.