PyTorch torch.roll 関数


Pytorch torch 参考手册Pytorch torch リファレンスマニュアル

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))

出力結果は次のとおりです。

tensor([6, 7, 0, 1, 2, 3, 4, 5])
tensor([2, 3, 4, 5, 6, 7, 0, 1])

Pytorch torch 参考手册Pytorch torch リファレンスマニュアル

その他の拡張