larray.AxisCollection.split_axes

AxisCollection.split_axes(self, axes=None, sep='_', names=None, regex=None)[source]

Split axes and returns a new collection

The split axes are inserted where the combined axis was.

Parameters
axesint, str, Axis or any combination of those, optional

axes to split. All labels must contain the given delimiter string. To split several axes at once, pass a list or tuple of axes to split. To set the names of resulting axes, use a {‘axis_to_split’: (new, axes)} dictionary. Defaults to all axes whose name contains the sep delimiter.

sepstr, optional

delimiter to use for splitting. Defaults to ‘_’. When regex is provided, the delimiter is only used on names if given as one string or on axis name if names is None.

namesstr or list of str, optional

names of resulting axes. Defaults to None.

regexstr, optional

use regex instead of delimiter to split labels. Defaults to None.

Returns
AxisCollection

Examples

>>> col = AxisCollection('a=a0,a1;b=b0..b2')
>>> col
AxisCollection([
    Axis(['a0', 'a1'], 'a'),
    Axis(['b0', 'b1', 'b2'], 'b')
])
>>> combined = col.combine_axes()
>>> combined
AxisCollection([
    Axis(['a0_b0', 'a0_b1', 'a0_b2', 'a1_b0', 'a1_b1', 'a1_b2'], 'a_b')
])
>>> combined.split_axes()
AxisCollection([
    Axis(['a0', 'a1'], 'a'),
    Axis(['b0', 'b1', 'b2'], 'b')
])

Split labels using regex

>>> combined = AxisCollection('a_b = a0b0..a1b2')
>>> combined
AxisCollection([
    Axis(['a0b0', 'a0b1', 'a0b2', 'a1b0', 'a1b1', 'a1b2'], 'a_b')
])
>>> combined.split_axes('a_b', regex='(\\w{2})(\\w{2})')
AxisCollection([
    Axis(['a0', 'a1'], 'a'),
    Axis(['b0', 'b1', 'b2'], 'b')
])

Split several axes at once

>>> combined = AxisCollection('a_b = a0_b0..a1_b1; c_d = c0_d0..c1_d1')
>>> combined
AxisCollection([
    Axis(['a0_b0', 'a0_b1', 'a1_b0', 'a1_b1'], 'a_b'),
    Axis(['c0_d0', 'c0_d1', 'c1_d0', 'c1_d1'], 'c_d')
])
>>> # equivalent to combined.split_axes() which split all axes
>>> # containing the delimiter defined by the argument `sep`
>>> combined.split_axes(['a_b', 'c_d'])
AxisCollection([
    Axis(['a0', 'a1'], 'a'),
    Axis(['b0', 'b1'], 'b'),
    Axis(['c0', 'c1'], 'c'),
    Axis(['d0', 'd1'], 'd')
])
>>> combined.split_axes({'a_b': ('A', 'B'), 'c_d': ('C', 'D')})
AxisCollection([
    Axis(['a0', 'a1'], 'A'),
    Axis(['b0', 'b1'], 'B'),
    Axis(['c0', 'c1'], 'C'),
    Axis(['d0', 'd1'], 'D')
])