torch.flip

torch.flip(input, dims) → Tensor
翻转dims数组中的维度
Parameters
input (Tensor) – the input tensor.
dims (a list or tuple) – axis to flip on

例子:
import torch
x = torch.arange(24).view(2, 3, 4)
x, torch.flip(x, [0]),torch.flip(x, [1]), torch.flip(x, [0, 1])

torch.flip(x, [0])翻转第0维度, torch.flip(x, [1])翻转第1维度, torch.flip(x, [0, 1])翻转第0和1维度

(tensor([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]],

     [[12, 13, 14, 15],
      [16, 17, 18, 19],
      [20, 21, 22, 23]]]),

tensor([[[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]],

     [[ 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]],

     [[20, 21, 22, 23],
      [16, 17, 18, 19],
      [12, 13, 14, 15]]]),

tensor([[[20, 21, 22, 23],
[16, 17, 18, 19],
[12, 13, 14, 15]],

     [[ 8,  9, 10, 11],
      [ 4,  5,  6,  7],
      [ 0,  1,  2,  3]]]))
posted @ 2021-10-22 10:11  哈哈哈喽喽喽  阅读(1166)  评论(0编辑  收藏  举报