scipp.arange#

scipp.arange(dim, start, stop=None, step=None, *, unit=<automatically deduced unit>, dtype=None)#

Creates a Variable with evenly spaced values within a given interval.

Values are generated within the half-open interval [start, stop). In other words, the interval including start but excluding stop.

start, stop, and step may be given as plain values or as 0-D variables. In the latter case this then implies the unit (the units of all arguments must be identical), but a different unit-scale can still be requested with the unit argument.

When all the types or dtypes of the input arguments are the same, the output will also have this dtype. This is different to numpy.arange() which will always produce 64-bit (int64 or float64) outputs.

Warning

The length of the output might not be numerically stable. See numpy.arange().

Parameters:
  • dim (str) – Dimension label.

  • start (NumberOrVar | _np.datetime64 | str) – Optional, the starting value of the sequence. Default=0.

  • stop (NumberOrVar | _np.datetime64 | str | None, default: None) – End of interval. The interval does not include this value, except in some (rare) cases where step is not an integer and floating-point round-off can come into play.

  • step (NumberOrVar | None, default: None) – Spacing between values.

  • unit (Unit | str | DefaultUnit | None, default: <automatically deduced unit>) – Unit of contents.

  • dtype (scipp.typing.DTypeLike) – Type of underlying data. By default, inferred from value argument.

Returns:

Variable – A variable of evenly spaced values.

Examples

>>> sc.arange('x', 4)
<scipp.Variable> (x: 4)      int64  [dimensionless]  [0, 1, 2, 3]
>>> sc.arange('x', 1, 5)
<scipp.Variable> (x: 4)      int64  [dimensionless]  [1, 2, 3, 4]
>>> sc.arange('x', 1, 5, 0.5)
<scipp.Variable> (x: 8)    float64  [dimensionless]  [1, 1.5, ..., 4, 4.5]
>>> sc.arange('x', 1, 5, unit='m')
<scipp.Variable> (x: 4)      int64              [m]  [1, 2, 3, 4]

Datetimes are also supported:

>>> sc.arange('t', '2000-01-01T01:00:00', '2000-01-01T01:01:30', 30 * sc.Unit('s'), dtype='datetime64')
<scipp.Variable> (t: 3)  datetime64              [s]  [2000-01-01T01:00:00, 2000-01-01T01:00:30, 2000-01-01T01:01:00]

Note that in this case the datetime start and stop strings implicitly define the unit. The step must have the same unit.