flopscope.

flopscope.numpy.moveaxis

fnp.moveaxis(a, source, destination)[flopscope source][numpy source]

Move axes of an array to new positions.

Adapted from NumPy docs np.moveaxis

Areacore
Typefree
NumPy Refnp.moveaxis
Cost
0
Flopscope Context

Move axes to new positions.

Other axes remain in their original order.

Parameters

a:flops.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:flops.ndarray

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

See also

Examples

>>> import flopscope.numpy as fnp
>>> x = flops.zeros((3, 4, 5))
>>> flops.moveaxis(x, 0, -1).shape
(4, 5, 3)
>>> flops.moveaxis(x, -1, 0).shape
(5, 3, 4)

These all achieve the same result:

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