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

Replace one, several or all axes of the array.

axes_to_replaceaxis ref or dict {axis ref: axis} or list of tuple (axis ref, axis) or list of 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.

new_axisAxis, optional

New axis if axes_to_replace contains a single axis reference.

inplacebool, optional

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


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


Array with axes replaced.

See also


rename one of several axes


>>> 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) # doctest: +SKIP
>>> # or
>>> arr.set_axes([('a', row), ('b', column)]) # doctest: +SKIP
>>> # 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