mygrad.swapaxes#

mygrad.swapaxes(a: ArrayLike, axis1: int, axis2: int, *, constant: bool | None = None) Tensor[source]#

Interchange two axes of a tensor.

Parameters:
aArrayLike

Input array.

axis1int

First axis.

axis2int

Second axis.

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:
mygrad.Tensor

Examples

>>> from mygrad import Tensor, swapaxes
>>> x = Tensor([[1, 2, 3]])
>>> swapaxes(x, 0, 1)
Tensor([[1],
       [2],
       [3]])
>>> x = Tensor([[[0, 1], [2, 3]], [[4, 5], [6, 7]]])
>>> x
Tensor([[[0, 1],
        [2, 3]],
       [[4, 5],
        [6, 7]]])
>>> swapaxes(x, 0, 2)
Tensor([[[0, 4],
        [2, 6]],
       [[1, 5],
        [3, 7]]])