PyTorch torch.permute 関数
torch.permutePyTorch でテンソルの次元を並べ替えるための関数です。
関数定義
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 リファレンスマニュアル