PyTorch torch.permute Function
Pytorch torch Reference Manual
torch.permuteis a function in PyTorch used to rearrange tensor dimensions.
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)
# Rearrange dimensions (2,3,4) -> (4,2,3)
y = x.permute(2, 0, 1)
print("After permute:", y.shape)
# Create a 3D tensor
x = torch.randn(2, 3, 4)
print("Original shape:", x.shape)
# Rearrange dimensions (2,3,4) -> (4,2,3)
y = x.permute(2, 0, 1)
print("After permute:", y.shape)
Other Extensions