UnitArray¶
UnitArray ¶
An exact array of values sharing a single physical unit.
All elements carry the same unit. Arithmetic operations between
two UnitArray instances check dimensional compatibility and
handle unit conversion automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
iterable of float
|
Numeric values, all in the given unit. |
required |
unit
|
str or CompoundUnit
|
Physical unit shared by all elements. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any element of |
Examples:
>>> import quantia as qu
>>> heights = qu.QA([1.75, 1.80, 1.65], 'm')
>>> heights.mean()
UnitFloat(1.7333..., 'm')
Boolean mask filtering:
dot ¶
Compute the dot product with another array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
o
|
UnitArray
|
Second operand. Must have the same length. |
required |
Returns:
| Type | Description |
|---|---|
UnitFloat
|
Scalar result with the product unit. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If arrays have different lengths. |
Examples:
max ¶
mean ¶
Return the arithmetic mean of all elements.
Returns:
| Type | Description |
|---|---|
UnitFloat
|
Mean in the array's unit. |
Examples:
min ¶
sum ¶
Return the sum of all elements.
Returns:
| Type | Description |
|---|---|
UnitFloat
|
Sum in the array's unit. |
Examples:
to ¶
Convert all elements to a different unit of the same quantity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str or CompoundUnit
|
Target unit. Must be dimensionally compatible. |
required |
Returns:
| Type | Description |
|---|---|
UnitArray
|
New array with all values expressed in |
Raises:
| Type | Description |
|---|---|
IncompatibleUnitsError
|
If |
Examples:
to_csv ¶
Write values to a single-column CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, 'Path']
|
|
required |
header
|
str, optional. Defaults to "value [<unit>]".
|
|
None
|