torch.rot90

torch.rot90(input, k=1, dims=(0, 1)) Tensor

在一个由dims轴指定的平面上,将一个n维张量旋转90度。如果k>0,旋转的方向是从第一个轴到第二个轴;如果k<0,旋转的方向则是从第二个轴到第一个轴。

参数
  • input (Tensor) – 需要输入的张量。

  • k (int) – 旋转次数,默认值为 1

  • dims (列表或元组) - 旋转的轴。 默认值为 [0, 1]

示例:

>>> x = torch.arange(4).view(2, 2)
>>> x
tensor([[0, 1],
        [2, 3]])
>>> torch.rot90(x, 1, [0, 1])
tensor([[1, 3],
        [0, 2]])

>>> x = torch.arange(8).view(2, 2, 2)
>>> x
tensor([[[0, 1],
         [2, 3]],

        [[4, 5],
         [6, 7]]])
>>> torch.rot90(x, 1, [1, 2])
tensor([[[1, 3],
         [0, 2]],

        [[5, 7],
         [4, 6]]])
本页目录