scipp.scalar(value, *, variance=None, unit=<automatically deduced unit>, dtype=None)#

Constructs a zero dimensional Variable with a unit and optional variance.

  • value (Any) – Initial value.

  • variance (Optional[Any], default: None) – Optional, initial variance.

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

  • dtype (scipp.typing.DTypeLike) – Optional, type of underlying data. By default, the dtype is inferred from the value argument. Cannot be specified for value types of Dataset or DataArray.


Variable – A scalar (zero-dimensional) Variable.


With deduced dtype and default unit:

>>> sc.scalar(3.14)
<scipp.Variable> ()    float64  [dimensionless]  3.14
>>> sc.scalar('a string')
<scipp.Variable> ()     string           <no unit>  "a string"

Or specifying a unit and dtype:

>>> sc.scalar(3.14, unit='m', dtype=int)
<scipp.Variable> ()      int64              [m]  3

Calling scalar with a list (or similar array-like object) will store that object in a scalar variable and not create an array variable:

>>> sc.scalar([1, 2, 3])
<scipp.Variable> ()   PyObject           <no unit>  [1, 2, 3]