PyTorch torch.roll 関数
torch.rollPyTorch でテンソルの要素をロールするために使用される関数です。
関数定義
torch.roll(input, shifts, dims)
使用例
実例
import torch
x = torch.arange(8)
# 前方に2つロール
print(torch.roll(x, 2))
# 後方に2つロール
print(torch.roll(x, -2))
x = torch.arange(8)
# 前方に2つロール
print(torch.roll(x, 2))
# 後方に2つロール
print(torch.roll(x, -2))
出力結果は次のとおりです。
tensor([6, 7, 0, 1, 2, 3, 4, 5]) tensor([2, 3, 4, 5, 6, 7, 0, 1])
その他の拡張
Pytorch torch リファレンスマニュアル