Dimension#
- class saiunit.Dimension(dims)#
Store the exponents of the 7 basic SI unit dimensions.
Represents a physical dimension as a combination of the 7 SI base dimensions: length, mass, time, electric current, temperature, amount of substance, and luminous intensity.
Provides arithmetic operations appropriate to dimensions: multiplication, division, powers, and equality testing.
- Parameters:
dims (sequence of float) – The exponents of the 7 basic SI unit dimensions, in order: [length, mass, time, current, temperature, substance, luminosity].
See also
get_or_create_dimensionFactory function (preferred over direct construction).
DIMENSIONLESSSingleton for dimensionless quantities.
Notes
Users should not use this class directly. Use get_or_create_dimension instead, which ensures only one
Dimensioninstance exists for every combination of exponents, allowing fast dimensionality checks withis.Examples
>>> import saiunit as u >>> length_dim = u.meter.dim >>> length_dim.get_dimension('m') 1.0 >>> length_dim.is_dimensionless False >>> u.DIMENSIONLESS.is_dimensionless True
- property dim#
Return the Dimension object itself.
This property allows uniform access to the dimension of an object via the
dimattribute, which works for Quantity, Unit, and Dimension objects alike.- Returns:
This Dimension instance.
- Return type:
Examples
>>> import saiunit as u >>> d = u.meter.dim >>> d.dim is d True
- get_dimension(d)[source]#
Return a specific dimension.
- Parameters:
d (str) – A string identifying the SI basic unit dimension. Can be either a description like “length” or a basic unit like “m” or “metre”.
- Returns:
dim – The dimensionality of the dimension d.
- Return type:
float
- property hash#
Calculate and return the hash value of the dimension.
This property memoizes the hash value for efficiency. Once calculated, the hash value is stored in the _hash attribute for future access. The hash is based on the binary representation of the dimensions array.
- Returns:
The hash value of the dimensions array.
- Return type:
Notes
The hash is only calculated once and then cached. This allows Dimension objects with the same dimensional values to have the same hash, supporting their use as dictionary keys and in sets.
- property is_dimensionless#
Check whether this Dimension is dimensionless.
- Returns:
True if all dimensional exponents are zero.
- Return type:
See also
DIMENSIONLESSSingleton dimensionless Dimension.
Notes
For performance, prefer checking
dim is DIMENSIONLESSinstead.Examples
>>> import saiunit as u >>> u.DIMENSIONLESS.is_dimensionless True >>> u.meter.dim.is_dimensionless False