PyTorch torch.permute function
PyTorch torch reference manual
torch.permute is a function in PyTorch used to permute the dimensions of a tensor.
Function definition
torch.permute(input, dims)
Usage examples
Example
import
torch
Create a 3D tensor
x
=
torch.
randn
(
2
,
3
,
4
)
(
"Original shape:"
,
x.
shape
)
Permute dimensions (2,3,4) -> (4,2,3)
y
=
x.
permute
(
2
,
0
,
1
)
(
"After permute:"
,
y.
shape
)