PyTorch torch.flipud 関数


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

torch.flipudPyTorch でテンソルを上下反転(垂直反転)させるための関数です。

関数定義

torch.flipud(input)

使用例

実例

import torch

# 2次元テンソルの上下反転
x = torch.arange(12).reshape(3, 4)
print("元のテンソル:")
print(x)

result = torch.flipud(x)
print("上下反転:")
print(result)

# 正方行列の上下反転
y = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print("n3x3 正方行列:")
print(y)

result = torch.flipud(y)
print("上下反転:")
print(result)

# 1次元テンソルの上下反転
z = torch.tensor([1, 2, 3, 4])
result = torch.flipud(z)
print("n1次元テンソル [1, 2, 3, 4]:")
print("上下反転:", result)

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

原始张量:
tensor([[ 0,  1,  2,  3],
        [ 4,  5,  6,  7],
        [ 8,  9, 10, 11]])
上下翻转:
tensor([[ 8,  9, 10, 11],
        [ 4,  5,  6,  7],
        [ 0,  1,  2,  3]])

3x3 方阵:
tensor([[1, 2, 3],
        [4, 5, 6],
        [7, 8, 9]])
上下翻转:
tensor([[7, 8, 9],
        [4, 5, 6],
        [1, 2, 3]])

一维张量 [1, 2, 3, 4]:
上下翻转: tensor([4, 3, 2, 1])

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

その他の拡張