This is a pre-release version (2.5.0.dev0+git20251130.2de293a). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / moveaxis

_ArrayFunctionDispatcher

numpy:moveaxis

source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/_core/numeric.py :1480

Signature

def   moveaxis ( a source destination )

Summary

Move axes of an array to new positions.

Extended Summary

Other axes remain in their original order.

Parameters

a : np.ndarray

The array whose axes should be reordered.

source : int or sequence of int

Original positions of the axes to move. These must be unique.

destination : int or sequence of int

Destination positions for each of the original axes. These must also be unique.

Returns

result : np.ndarray

Array with moved axes. This array is a view of the input array.

Examples

import numpy as np
x = np.zeros((3, 4, 5))
np.moveaxis(x, 0, -1).shape
np.moveaxis(x, -1, 0).shape
These all achieve the same result:
np.transpose(x).shape
np.swapaxes(x, 0, -1).shape
np.moveaxis(x, [0, 1], [-1, -2]).shape
np.moveaxis(x, [0, 1, 2], [-1, -2, -3]).shape

See also

swapaxes

Interchange two axes of an array.

transpose

Permute the dimensions of an array.

Aliases

  • numpy.moveaxis