moveaxis

moveaxis(x: array, source: int | Tuple[int, ...], destination: int | Tuple[int, ...], /) array

Moves array axes to new positions, while leaving other axes in their original positions.

Parameters:
  • x (array) – input array.

  • source (Union[int, Tuple[int, ...]]) – axis (or axes) to move. Provided source axes must be unique. A valid axis must be an integer on the interval [-N, N), where N is the number of axes in x. If an axis is specified as a negative integer, the function must determine the axis along which to perform the operation by counting backward from the last axis (where -1 refers to the last axis). If provided an invalid axis, the function must raise an exception.

  • destination (Union[int, Tuple[int, ...]]) – axis (or axes) defining the desired position(s) for each respective source axis index. Provided destination axes must be unique. A valid axis must be an integer on the interval [-N, N), where N is the number of axes in x. If an axis is specified as a negative integer, the function must determine the axis along which to perform the operation by counting backward from the last axis (where -1 refers to the last axis). If provided an invalid axis, the function must raise an exception.

Returns:

out (array) – an array containing reordered axes. The returned array must have the same data type as x.

Notes

New in version 2023.12.