PyTorch torch.flip Function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.flipIt is a function in PyTorch used to flip a tensor along specified dimensions.

Function Definition

torch.flip(input, dims)

Usage Example

Example

import torch

x = torch.arange(8).reshape(2, 4)

print("Original:")
print(x)

print("Horizontal flip:")
print(torch.flip(x, dims=[1]))

print("Vertical flip:")
print(torch.flip(x, dims=[0]))

The output result is:

原始:
tensor([[0, 1, 2, 3],
        [4, 5, 6, 7]])
水平翻转:
tensor([[3, 2, 1, 0],
        [7, 6, 5, 4]])
垂直翻转:
tensor([[4, 5, 6, 7],
        [0, 1, 2, 3]])

Pytorch torch 参考手册Pytorch torch Reference Manual

Other Extensions