評價此頁

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]]])