asarray#
- class saiunit.math.asarray(a, dtype=None, order=None, unit=None)#
Convert the input to a quantity or array.
If
unitis provided, the input is checked for compatible units and converted accordingly. Ifunitis not provided, the unit is inferred from the input data.The function
arrayis an alias forasarray.- Parameters:
a (
Any) – Input data, in any form that can be converted to an array. When a list ofQuantityobjects 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.unit (saiunit.Unit |
None) – Target unit of the returnedQuantity. 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
ahave incompatible units, or ifunitis specified but does not match the dimension ofa.
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")