scipp.scalar#

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

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

Parameters:
  • value (Any) – Initial value.

  • variance (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.

Returns:

Variable – A scalar (zero-dimensional) Variable.

Examples

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]