spekk.transformations.axis.Axis#

class spekk.transformations.axis.Axis(dimension: str, keep: bool = False, becomes: Tuple[str] = ())[source]#

Bases: object

A placeholder for an array axis, given by the name of that axis (dimension).

In the context of a transformation, an Axis is a way to get the concrete axis-index of an array, and also to specify what happens to that dimension in the transformation.

By default, the dimension is removed, which makes sense for common operations like numpy.sum() or numpy.mean(). If you want to keep the dimension, set keep=True. If you want to replace the dimension with something else, set becomes=("something", "else").

__init__(dimension: str, keep: bool = False, becomes: Tuple[str] = ()) None#

Methods

__init__(dimension[, keep, becomes])

new_dimensions(dimensions)

Given a sequence of dimensions return the new dimensions after this Axis has been parsed.

Attributes

becomes

If set, the dimension is replaced in the spec with the given dimensions.

keep

Whether to keep the dimension in the spec after referencing it (default False, i.e. the dimension is removed from the spec).

dimension

The referenced dimension

becomes: Tuple[str] = ()#

If set, the dimension is replaced in the spec with the given dimensions.

dimension: str#

The referenced dimension

keep: bool = False#

Whether to keep the dimension in the spec after referencing it (default False, i.e. the dimension is removed from the spec).

new_dimensions(dimensions: Sequence[str]) Tuple[str][source]#

Given a sequence of dimensions return the new dimensions after this Axis has been parsed.

By default, the dimension is removed. If keep=True, the dimension is kept. If becomes is set, the dimension is replaced with the dimensions defined by the becomes field.

Examples:

>>> old_dimensions = ("a", "b", "c")
>>> Axis("b").new_dimensions(old_dimensions)
('a', 'c')
>>> Axis("b", keep=True).new_dimensions(old_dimensions)
('a', 'b', 'c')
>>> Axis("b", becomes=("x", "y")).new_dimensions(old_dimensions)
('a', 'x', 'y', 'c')