评价此页

torch.rot90#

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

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

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

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

  • dims (listtuple) – 旋转轴。默认为 [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]]])