spekk.transformations.axis.Axis#
- class spekk.transformations.axis.Axis(dimension: str, keep: bool = False, becomes: Tuple[str] = ())[source]#
Bases:
objectA placeholder for an array axis, given by the name of that axis (dimension).
In the context of a transformation, an
Axisis 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()ornumpy.mean(). If you want to keep the dimension, setkeep=True. If you want to replace the dimension with something else, setbecomes=("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
Axishas been parsed.Attributes
If set, the dimension is replaced in the spec with the given dimensions.
Whether to keep the dimension in the spec after referencing it (default
False, i.e. the dimension is removed from the spec).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
Axishas been parsed.By default, the dimension is removed. If
keep=True, the dimension is kept. Ifbecomesis set, the dimension is replaced with the dimensions defined by thebecomesfield.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')