larray.Array.combine_axes

Array.combine_axes(axes=None, sep='_', wildcard=False) Array[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.

Returns
Array

Array with combined axes.

Examples

>>> arr = ndtest((2, 3))
>>> arr
a\b  b0  b1  b2
 a0   0   1   2
 a1   3   4   5
>>> arr.combine_axes()
a_b  a0_b0  a0_b1  a0_b2  a1_b0  a1_b1  a1_b2
         0      1      2      3      4      5
>>> arr.combine_axes(sep='/')
a/b  a0/b0  a0/b1  a0/b2  a1/b0  a1/b1  a1/b2
         0      1      2      3      4      5
>>> arr = ndtest((2, 2, 2, 2))
>>> arr
 a   b  c\d  d0  d1
a0  b0   c0   0   1
a0  b0   c1   2   3
a0  b1   c0   4   5
a0  b1   c1   6   7
a1  b0   c0   8   9
a1  b0   c1  10  11
a1  b1   c0  12  13
a1  b1   c1  14  15
>>> arr.combine_axes(('a', 'c'))
  a_c  b\d  d0  d1
a0_c0   b0   0   1
a0_c0   b1   4   5
a0_c1   b0   2   3
a0_c1   b1   6   7
a1_c0   b0   8   9
a1_c0   b1  12  13
a1_c1   b0  10  11
a1_c1   b1  14  15
>>> arr.combine_axes({('a', 'c'): 'ac'})
   ac  b\d  d0  d1
a0_c0   b0   0   1
a0_c0   b1   4   5
a0_c1   b0   2   3
a0_c1   b1   6   7
a1_c0   b0   8   9
a1_c0   b1  12  13
a1_c1   b0  10  11
a1_c1   b1  14  15

# make several combinations at once

>>> arr.combine_axes([('a', 'c'), ('b', 'd')])
a_c\b_d  b0_d0  b0_d1  b1_d0  b1_d1
  a0_c0      0      1      4      5
  a0_c1      2      3      6      7
  a1_c0      8      9     12     13
  a1_c1     10     11     14     15
>>> arr.combine_axes({('a', 'c'): 'ac', ('b', 'd'): 'bd'})
ac\bd  b0_d0  b0_d1  b1_d0  b1_d1
a0_c0      0      1      4      5
a0_c1      2      3      6      7
a1_c0      8      9     12     13
a1_c1     10     11     14     15