linspace

Contents

linspace#

class saiunit.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 (Union[saiunit.Quantity, Array, ndarray, number, bool]) – The starting value of the sequence.

  • stop (Union[saiunit.Quantity, Array, ndarray, number, bool]) – 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 (Optional[bool]) – If True, stop is the last sample. Otherwise, it is not included. Default is True.

  • retstep (Optional[bool]) – If True, return (samples, step), where step is the spacing between samples.

  • dtype (Union[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:

Union[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")