treams.util.AnnotatedArray

class treams.util.AnnotatedArray(array, ann=(), /, **kwargs)

Array that keeps track of annotations for each dimension.

This class acts mostly like numpy arrays, but it is enhanced by the following functionalities:

  • Annotations are added to each dimension

  • Annotations are compared and preserved for numpy (generalized) numpy.ufunc (like numpy.add, numpy.exp, numpy.matmul and many more “standard” mathematical functions)

  • Special ufunc methods, like numpy.ufunc.reduce(), are supported

  • A growing subset of other numpy functions are supported, like numpy.linalg.solve()

  • Keywords can be specified as scale are also index into, when index the AnnotatedArray

  • Annotations can also be exposed as properties

Example

>>> a = AnnotatedArray([[0, 1], [2, 3]], ({"a": 1}, {"b": 2}))
>>> b = AnnotatedArray([1, 2], ({"b": 2},))
>>> a @ b
AnnotatedArray(
    [2, 8],
    AnnotationSequence(AnnotationDict({'a': 1})),
)

The interoperability with numpy is implemented using Writing custom array containers by defining __array__(), __array_ufunc__(), and __array_function__().

Attributes

T

Transpose.

ann

Array annotations.

imag

Imaginary part of the array.

ndim

Number of array dimensions.

real

Real part of the array.

shape

Array shape.

size

Array size.

Methods

__abs__()

__add__(other)

__and__(other)

__array__([dtype])

Convert to an numpy array.

__array_function__(func, types, args, kwargs)

Function calls on the array.

__array_ufunc__(ufunc, method, *inputs, **kwargs)

Implement ufunc API.

__divmod__(other)

__eq__(other)

Return self==value.

__floordiv__(other)

__ge__(other)

Return self>=value.

__getitem__(key)

Get an item from the AnnotatedArray.

__gt__(other)

Return self>value.

__invert__()

__le__(other)

Return self<=value.

__len__()

__lshift__(other)

__lt__(other)

Return self<value.

__matmul__(other)

__mod__(other)

__mul__(other)

__ne__(other)

Return self!=value.

__neg__()

__or__(other)

Return self|value.

__pos__()

__pow__(other)

__repr__()

String representation.

__rshift__(other)

__setitem__(key, value)

Set values.

__str__()

String of the array itself.

__sub__(other)

__truediv__(other)

__xor__(other)

all([axis, dtype, out, keepdims, where])

Test if all elements (along an axis) are True.

any([axis, dtype, out, keepdims, where])

Test if any element (along an axis) is True.

astype(*args, **kwargs)

Return array as given type.

conj(*args, **kwargs)

Complex conjugate elementwise.

conjugate(*args, **kwargs)

Complex conjugate elementwise.

cumprod([axis, dtype, out])

Cumulative product of elements (along an axis).

cumsum([axis, dtype, out])

Cumulative sum of elements (along an axis).

diagonal([offset, axis1, axis2])

Get the diagonal of the array.

flatten([order])

Flatten array to one dimension.

max([axis, out, keepdims, initial, where])

Maximum (along an axis).

min([axis, out, keepdims, initial, where])

Minimum (along an axis).

prod([axis, dtype, out, keepdims, initial, ...])

Product of elements (along an axis).

relax(*args[, mro])

Try creating AnnotatedArray subclasses if possible.

sum([axis, dtype, out, keepdims, initial, where])

Sum of elements (along an axis).

swapaxes(axis1, axis2)

trace([offset, axis1, axis2, dtype, out])

Trace of an array.

transpose([axes])

Transpose array dimensions.

__le__(other)

Return self<=value.

__lt__(other)

Return self<value.

__abs__()

__pos__()

__neg__()

__divmod__(other)

__or__(other)

Return self|value.

__lshift__(other)

__rshift__(other)

__add__(other)

__and__(other)

__sub__(other)

__xor__(other)

__ge__(other)

Return self>=value.

__gt__(other)

Return self>value.

__invert__()

__ne__(other)

Return self!=value.

__pow__(other)

__floordiv__(other)

__truediv__(other)

__mul__(other)

__eq__(other)

Return self==value.

__mod__(other)