mygrad.moveaxis#

mygrad.moveaxis(a: ArrayLike, source: Union[int, Tuple[int, ...]], destination: Union[int, Tuple[int, ...]], *, constant: Optional[bool] = None) Tensor[source]#

Move axes of a tensor to new positions. Other axes remain in their original order.

Parameters
aArrayLike

The array whose axes should be reordered.

sourceUnion[int, Sequence[int]]

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

destinationUnion[int, Sequence[int]]

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

constantOptional[bool]

If True, this tensor is treated as a constant, and thus does not facilitate back propagation (i.e. constant.grad will always return None).

Defaults to False for float-type data. Defaults to True for integer-type data.

Integer-type tensors must be constant.

Returns
——-
resultmygrad.Tensor

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

Examples

>>> from mygrad import zeros, moveaxis
>>> x = zeros((3, 4, 5))
>>> moveaxis(x, 0, -1).shape
(4, 5, 3)
>>> moveaxis(x, -1, 0).shape
(5, 3, 4)
>>> moveaxis(x, [0, 1], [-1, -2]).shape
(5, 4, 3)