PyTorch torch.flip 関数


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

torch.flipPyTorch において、指定した次元に沿ってテンソルを反転するための関数です。

関数定義

torch.flip(input, dims)

使用例

実例

import torch

x = torch.arange(8).reshape(2, 4)

print("元:")
print(x)

print("水平反転:")
print(torch.flip(x, dims=[1]))

print("垂直反転:")
print(torch.flip(x, dims=[0]))

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

原始:
tensor([[0, 1, 2, 3],
        [4, 5, 6, 7]])
水平翻转:
tensor([[3, 2, 1, 0],
        [7, 6, 5, 4]])
垂直翻转:
tensor([[4, 5, 6, 7],
        [0, 1, 2, 3]])

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

その他の拡張