asarray

Contents

asarray#

class saiunit.math.asarray(a, dtype=None, order=None, unit=None)#

Convert the input to a quantity or array.

If unit is provided, the input is checked for compatible units and converted accordingly. If unit is not provided, the unit is inferred from the input data.

The function array is an alias for asarray.

Parameters:
  • a (Any) – Input data, in any form that can be converted to an array. When a list of Quantity objects is given, all elements must share the same dimension.

  • dtype (str | type[Any] | dtype | SupportsDType | None) – By default, the data-type is inferred from the input data.

  • order (str | None) – Memory layout. Defaults to 'K'.

  • unit (saiunit.Unit | None) – Target unit of the returned Quantity. When given, all elements are converted to this unit.

Returns:

out – Array interpretation of a.

Return type:

saiunit.Quantity | Array | None

Raises:

UnitMismatchError – If elements of a have incompatible units, or if unit is specified but does not match the dimension of a.

Examples

>>> import saiunit as u
>>> u.math.array([1, 2, 3])
Array([1, 2, 3], dtype=int32)
>>> u.math.array([1, 2, 3] * u.meter)
Quantity([1 2 3], "m")
>>> u.math.asarray([1 * u.meter, 2 * u.meter])
Quantity([1 2], "m")