linspace

Contents

linspace#

class brainunit.math.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.

Parameters:
  • start (saiunit.Quantity | Array | ndarray | bool | number | bool | int | float | complex) – The starting value of the sequence.

  • stop (saiunit.Quantity | Array | ndarray | bool | number | bool | int | float | complex) – The end value of the sequence. Must have the same unit as start when either is a Quantity.

  • num (int) – Number of samples to generate. Default is 50.

  • endpoint (bool | None) – If True, stop is the last sample. Otherwise, it is not included. Default is True.

  • retstep (bool | None) – If True, return (samples, step), where step is the spacing between samples.

  • dtype (str | type[Any] | dtype | SupportsDType | None) – The type of the output array.

Returns:

samplesnum equally spaced samples in the closed interval [start, stop] or the half-open interval [start, stop).

Return type:

saiunit.Quantity | Array

Raises:

UnitMismatchError – If start and stop do not share the same unit.

Examples

>>> import saiunit as u
>>> u.math.linspace(0, 10, 5)
Array([ 0. ,  2.5,  5. ,  7.5, 10. ], dtype=float32)
>>> u.math.linspace(0 * u.meter, 10 * u.meter, 5)
Quantity([ 0.   2.5  5.   7.5 10. ], "m")