- qunits. Quantity ( value , unit=None )[source]
-
A value with a
Unit. The value is a float or a numpy array of floats. Quantities are usually created by multiplying a number or an array with a unit, e.g.3 * u.m, and support:+and-, also in place, with quantities of the same dimension and context. The result is in the unit of the left operand. Numbers and arrays can only be added to and subtracted from dimensionless quantities without context, e.g.0.5 * u.m / u.km + 1.*and/, also in place, with numbers, arrays, units and quantities.np.add,np.subtract,np.multiplyandnp.divide, andnp.sin,np.cosandnp.tanof angles, i.e. dimensionless quantities with the contextContext.ANGLEsuch asu.rad.
Other numpy functions and the methods
reduce,accumulate,outerandatof the numpy functions, e.g.np.sum, raise aNotImplementedError.Printed quantities show scalar values rounded to 15 significant digits, e.g.
5.225 kminstead of5.2250000000000005 km, which hides the rounding errors of the binary floats. The values themselves are not rounded. Arrays are printed with the precision of numpy.- Parameters:
-
- valuearray_like | Quantity
The value, a number, an array-like or a quantity. Numbers are converted to
floatand array-likes to numpy arrays offloat64.- unitUnit | None
The unit. A quantity
valueis converted to it. Defaults to the unit of a quantityvalue, and to the dimensionless unitu.Iotherwise.
- Attributes:
-
- TQuantity
The quantity with the transposed array value. A quantity with a scalar value is returned unchanged.
- ctypes_ctypes[int]
The ctypes interface of the array value. Raises a
NotImplementedErrorfor a scalar value.- datamemoryview
A
memoryviewof the array value. Raises aNotImplementedErrorfor a scalar value.- dtypenp.dtype[np.float64]
The data type of the value,
float64.- flagsflagsobj
The memory layout flags of the array value. Raises a
NotImplementedErrorfor a scalar value.- itemsizeint
The size of one element of the value in bytes.
- mfloat | NDArray[np.float64]
The value of the quantity in its unit, same as
value.- magnitudefloat | NDArray[np.float64]
The value of the quantity in its unit, same as
value.- nbytesint
The size of all elements of the value in bytes.
- ndimint
The number of array dimensions of the value, 0 for a scalar value.
- shapetuple[int, ...]
The shape of the value,
()for a scalar value.- sizeint
The number of elements of the value, 1 for a scalar value.
- stridestuple[int, ...]
The strides of the array value,
()for a scalar value.- unitUnit
The
Unitof the quantity.- valuefloat | NDArray[np.float64]
The value of the quantity in its unit, a float or a numpy array of floats.
- Raises:
-
- ValueError
If
valueis a quantity with another dimension or context thanunit.