mygrad.transpose#
- mygrad.transpose(a: ArrayLike, *axes: int, constant: bool | None = None) Tensor [source]#
Permute the dimensions of a tensor.
- Parameters:
- aArrayLike
The tensor to be transposed
- axesint
By default, reverse the dimensions, otherwise permute the axes according to the values given.
- constantOptional[bool]
If
True
, this tensor is treated as a constant, and thus does not facilitate back propagation (i.e.constant.grad
will always returnNone
).Defaults to
False
for float-type data. Defaults toTrue
for integer-type data.Integer-type tensors must be constant.
- Returns:
- mygrad.Tensor
a with its axes permuted. A new tensor is returned.
Examples
>>> import mygrad as mg >>> a = mg.tensor([[1, 2], [3, 4]]) >>> a Tensor([[1, 2], [3, 4]]) >>> a.transpose() Tensor([[1, 3], [2, 4]]) >>> a.transpose((1, 0)) Tensor([[1, 3], [2, 4]]) >>> a.transpose(1, 0) Tensor([[1, 3], [2, 4]])