torch.flip¶
- torch.flip(input, dims) Tensor ¶
沿著 dims 中給定的軸反轉 n 維 tensor 的順序。
注意
torch.flip 會複製
input
的資料。這與 NumPy 的 np.flip 不同,後者會在恆定時間內返回視圖。由於複製 tensor 的資料比查看該資料需要更多的工作,因此 torch.flip 預計會比 np.flip 慢。範例
>>> 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]]])