Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.flip function

PyTorch torch.flip function


PyTorch torch reference manual PyTorch torch reference manual

torch.flip is a PyTorch function for flipping a tensor along a specified dimension.

Function definition

torch.flip(input, dims)


Usage examples

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 is:

原始:

tensor([[0, 1, 2, 3],

        [4, 5, 6, 7]])

Horizontal flip:

tensor([[3, 2, 1, 0],

        [7, 6, 5, 4]])

Vertical flip:

tensor([[4, 5, 6, 7],

        [0, 1, 2, 3]])


PyTorch torch reference manual PyTorch torch reference manual