Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.permute function

PyTorch torch.permute function


PyTorch torch reference manual 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

)

print

(

"Original shape:"

,

x.

shape

)

Permute dimensions (2,3,4) -> (4,2,3)

y

=

x.

permute

(

2

,

0

,

1

)

print

(

"After permute:"

,

y.

shape

)


PyTorch torch reference manual PyTorch torch reference manual