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 or num+1 depending on whether endpoint is True or False, 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), and d = 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 is False, the function must generate a sequence of num+1 evenly spaced numbers starting with start and ending with stop and exclude the stop from the returned array such that the returned array consists of evenly spaced numbers over the half-open interval [start, stop). If endpoint is True, the output array must consist of evenly spaced numbers over the closed interval [start, stop]. Default: True.

    Note

    The step size changes when endpoint is False.

  • 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 is None,

    • if either start or stop is a complex number, the output data type must be the default complex floating-point data type.

    • if both start and stop are real-valued, the output data type must be the default real-valued floating-point data type.

    Default: None.

    Note

    If dtype is not None, conversion of start and stop 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 or stop 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.