scipp.array#

scipp.array(*, dims, values, variances=None, unit=<automatically deduced unit>, dtype=None)#

Constructs a Variable with given dimensions, containing given values and optional variances.

Dimension and value shape must match. Only keyword arguments accepted.

Parameters:
  • dims (Iterable[str]) – Dimension labels

  • values (numpy.typing.ArrayLike) – Initial values.

  • variances (numpy.typing.ArrayLike) – Initial variances, must be same shape and size as 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 values argument.

Returns:

Variable – A variable with the given values.

Examples

>>> sc.array(dims=['x'], values=[1, 2, 3])
<scipp.Variable> (x: 3)      int64  [dimensionless]  [1, 2, 3]

Multiple dimensions:

>>> sc.array(dims=['x', 'y'], values=[[1, 2, 3], [4, 5, 6]])
<scipp.Variable> (x: 2, y: 3)      int64  [dimensionless]  [1, 2, ..., 5, 6]

DType upcasting:

>>> sc.array(dims=['x'], values=[1, 2, 3.0])
<scipp.Variable> (x: 3)    float64  [dimensionless]  [1, 2, 3]

Manually specified dtype:

>>> sc.array(dims=['x'], values=[1, 2, 3], dtype=float)
<scipp.Variable> (x: 3)    float64  [dimensionless]  [1, 2, 3]

Set unit:

>>> sc.array(dims=['x'], values=[1, 2, 3], unit='m')
<scipp.Variable> (x: 3)      int64              [m]  [1, 2, 3]

Setting variances:

>>> sc.array(dims=['x'], values=[1.0, 2.0, 3.0], variances=[0.1, 0.2, 0.3])
<scipp.Variable> (x: 3)    float64  [dimensionless]  [1, 2, 3]  [0.1, 0.2, 0.3]