TUTORIALAI & dataFETCHED
PyTorch torch.permute 函数
PyTorch torch.permute 函数 Pytorch torch 参考手册 torch.permute 是 PyTorch 中用于重新排列张量维度的函数。 函数定义 torch.permute(input, dims) 使用示例 实例 [mycode4 type='python'] import torch # 创建 3D 张量 x = torch.randn(2, 3, 4) pr..
Updated 7/16/2026
Tutorial detail pages default to noindex.
PyTorch torch.permute 函数
torch.permute 是 PyTorch 中用于重新排列张量维度的函数。
函数定义
torch.permute(input, dims)
使用示例
实例
import torch
# 创建 3D 张量
x = torch.randn(2, 3, 4)
print("原始形状:", x.shape)
# 重新排列维度 (2,3,4) -> (4,2,3)
y = x.permute(2, 0, 1)
print("permute 后:", y.shape)
# 创建 3D 张量
x = torch.randn(2, 3, 4)
print("原始形状:", x.shape)
# 重新排列维度 (2,3,4) -> (4,2,3)
y = x.permute(2, 0, 1)
print("permute 后:", y.shape)
Pytorch torch 参考手册