larray.AxisCollection.combine_axes

AxisCollection.combine_axes(axes=None, sep='_', wildcard=False, front_if_spread=False) AxisCollection[source]

Combine several axes into one.

Parameters
axestuple, list, AxisCollection of axes or list of combination of those or dict, optional

axes to combine. Tuple, list or AxisCollection will combine several axes into one. To chain several axes combinations, pass a list of tuple/list/AxisCollection of axes. To set the name(s) of resulting axis(es), use a {(axes, to, combine): ‘new_axis_name’} dictionary. Defaults to all axes.

sepstr, optional

delimiter to use for combining. Defaults to ‘_’.

wildcardbool, optional

whether to produce a wildcard axis even if the axes to combine are not. This is much faster, but loose axes labels.

front_if_spreadbool, optional

whether to move the combined axis at the front (it will be the first axis) if the combined axes are not next to each other.

Returns
AxisCollection

New AxisCollection with combined axes.

Examples

>>> axes = AxisCollection('a=a0,a1;b=b0..b2')
>>> axes
AxisCollection([
    Axis(['a0', 'a1'], 'a'),
    Axis(['b0', 'b1', 'b2'], 'b')
])
>>> axes.combine_axes()
AxisCollection([
    Axis(['a0_b0', 'a0_b1', 'a0_b2', 'a1_b0', 'a1_b1', 'a1_b2'], 'a_b')
])
>>> axes.combine_axes(sep='/')
AxisCollection([
    Axis(['a0/b0', 'a0/b1', 'a0/b2', 'a1/b0', 'a1/b1', 'a1/b2'], 'a/b')
])
>>> axes += AxisCollection('c=c0..c2;d=d0,d1')
>>> axes.combine_axes(('a', 'c'))
AxisCollection([
    Axis(['a0_c0', 'a0_c1', 'a0_c2', 'a1_c0', 'a1_c1', 'a1_c2'], 'a_c'),
    Axis(['b0', 'b1', 'b2'], 'b'),
    Axis(['d0', 'd1'], 'd')
])
>>> axes.combine_axes({('a', 'c'): 'ac'})
AxisCollection([
    Axis(['a0_c0', 'a0_c1', 'a0_c2', 'a1_c0', 'a1_c1', 'a1_c2'], 'ac'),
    Axis(['b0', 'b1', 'b2'], 'b'),
    Axis(['d0', 'd1'], 'd')
])

# make several combinations at once

>>> axes.combine_axes([('a', 'c'), ('b', 'd')])
AxisCollection([
    Axis(['a0_c0', 'a0_c1', 'a0_c2', 'a1_c0', 'a1_c1', 'a1_c2'], 'a_c'),
    Axis(['b0_d0', 'b0_d1', 'b1_d0', 'b1_d1', 'b2_d0', 'b2_d1'], 'b_d')
])
>>> axes.combine_axes({('a', 'c'): 'ac', ('b', 'd'): 'bd'})
AxisCollection([
    Axis(['a0_c0', 'a0_c1', 'a0_c2', 'a1_c0', 'a1_c1', 'a1_c2'], 'ac'),
    Axis(['b0_d0', 'b0_d1', 'b1_d0', 'b1_d1', 'b2_d0', 'b2_d1'], 'bd')
])