larray.Array.set_axes

Array.set_axes(axes_to_replace=None, new_axis=None, inplace=False, **kwargs) Array[source]

Replace one, several or all axes of the array.

Parameters
axes_to_replaceaxis ref or dict {axis ref: axis} or list of (tuple or Axis) or AxisCollection

Axes to replace. If a single axis reference is given, the new_axis argument must be provided. If a list of Axis or an AxisCollection is given, all axes will be replaced by the new ones. In that case, the number of new axes must match the number of the old ones. If a list of tuple is given, it must be pairs of (reference to old axis, new axis).

new_axisAxis, optional

New axis if axes_to_replace contains a single axis reference.

inplacebool, optional

Whether to modify the original object or return a new array and leave the original intact. Defaults to False.

**kwargsAxis

New axis for each axis to replace given as a keyword argument.

Returns
Array

Array with axes replaced.

See also

rename

rename one of several axes

Examples

>>> arr = ndtest((2, 3))
>>> arr
a\b  b0  b1  b2
 a0   0   1   2
 a1   3   4   5
>>> row = Axis(['r0', 'r1'], 'row')
>>> column = Axis(['c0', 'c1', 'c2'], 'column')

Replace one axis (second argument new_axis must be provided)

>>> arr.set_axes('a', row)
row\b  b0  b1  b2
   r0   0   1   2
   r1   3   4   5

Replace several axes (keywords, list of tuple or dictionary)

>>> arr.set_axes(a=row, b=column) 
>>> # or
>>> arr.set_axes([('a', row), ('b', column)]) 
>>> # or
>>> arr.set_axes({'a': row, 'b': column})
row\column  c0  c1  c2
        r0   0   1   2
        r1   3   4   5

Replace all axes (list of axes or AxisCollection)

>>> arr.set_axes([row, column])
row\column  c0  c1  c2
        r0   0   1   2
        r1   3   4   5
>>> arr2 = ndtest([row, column])
>>> arr.set_axes(arr2.axes)
row\column  c0  c1  c2
        r0   0   1   2
        r1   3   4   5