antupy.Array#

class antupy.Array(_value: ndarray | list | Array | None = None, _unit: str | Unit | None = None)[source]#

A container for homogeneous numerical data with associated physical units.

The Array class represents collections of values (like time series, parametric variables, or measurement arrays) that share the same physical unit. It provides automatic unit conversion and arithmetic operations while preserving dimensional consistency.

Parameters:
  • value (np.ndarray, list, or None, optional) – Input values as array-like or None. Default is None.

  • unit (str, Unit, or None, optional) – Physical unit as string or Unit object. Default is None.

  • _value (ndarray | list | Array | None)

  • _unit (str | Unit | None)

value#

The numerical values as a numpy array.

Type:

np.ndarray

unit#

The physical unit associated with all values.

Type:

Unit

Raises:
  • TypeError – If units are incompatible during arithmetic operations.

  • ValueError – If requested unit conversion is not dimensionally consistent.

Parameters:

Examples

Basic usage:

>>> from antupy import Array
>>> temperatures = Array([20.0, 25.0, 30.0], "°C")
>>> print(temperatures)
[20. 25. 30.] [°C]

Arithmetic operations with unit conversion:

>>> mass1 = Array([1.0, 2.0, 3.0], "kg")
>>> mass2 = Array([500, 1000, 1500], "g")
>>> total_mass = mass1 + mass2  # Automatic conversion
>>> print(total_mass)
[1.5 2.5 3.5] [kg]

Unit conversion:

>>> print(total_mass.set_unit("g"))
[1500. 2500. 3500.] [g]
>>> print(total_mass.get_value("ton"))
[0.0015 0.0025 0.0035]

Iteration and indexing:

>>> for temp in temperatures[:2]:
...     print(f"Temperature: {temp}")
Temperature: 20.0 [°C]
Temperature: 25.0 [°C]

Notes

All arithmetic operations automatically handle unit conversions when dimensions are compatible. Incompatible operations raise TypeError.

See also

Var

For handling single values with units

antupy.units.Unit

The underlying unit representation class

__init__(_value: ndarray | list | Array | None = None, _unit: str | Unit | None = None) None#
Parameters:
Return type:

None

Methods

__init__([_value, _unit])

argmax()

argmin()

compatible()

Return a list of compatible units for the variable unit.

cumsum([unit])

get_value([unit])

Method to obtain the value of the variable in the requested unit.

gv([unit])

Alias for self.get_value()

max([unit])

mean([unit])

min([unit])

prod([unit])

round([decimals, unit])

set_unit([unit])

Set the primary unit of the variable.

sort([unit])

std([unit])

su([unit])

Alias of self.set_unit

sum([unit])

var([unit])

Attributes

u

Property to obtain the label unit of the variable

v

Property to obtain the value of the variable in its label unit.

value

unit