nlcpy.moveaxis

nlcpy.moveaxis(a, source, destination)[source]

Moves axes of an array to new positions.

Other axes remain in their original order.

Parameters
andarray

The array whose axes should be reordered.

sourceint or sequence of ints

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

destinationint or sequence of ints

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

Returns
resultndarray

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

See also

transpose

Permutes the dimensions of an array.

Examples

>>> import nlcpy as vp
>>> x = vp.zeros((3, 4, 5))
>>> vp.moveaxis(x, 0, -1).shape
(4, 5, 3)
>>> vp.moveaxis(x, -1, 0).shape
(5, 3, 4)

# These all achieve the same result:

>>> vp.transpose(x).shape
(5, 4, 3)
>>> vp.moveaxis(x, [0, 1], [-1, -2]).shape
(5, 4, 3)
>>> vp.moveaxis(x, [0, 1, 2], [-1, -2, -3]).shape
(5, 4, 3)