評價此頁

torch.flip#

torch.flip(input, dims) Tensor#

沿給定的 `dims` 軸反轉 n 維張量的順序。

注意

torch.flip 會複製 input 的資料。這與 NumPy 的 np.flip 不同,後者以恆定的時間返回一個檢視。由於複製張量資料比檢視資料更耗時,因此 torch.flip 預計會比 np.flip 慢。

引數
  • input (Tensor) – 輸入張量。

  • dims (listtuple) – 要翻轉的軸

示例

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

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

        [[ 2,  3],
         [ 0,  1]]])