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

PyTorch torch.flipud function

PyTorch torch.flipud function


PyTorch torch reference manual PyTorch torch reference manual

torch.flipud A function in PyTorch for flipping a tensor upside down (vertically).

Function definition

torch.flipud(input)


Usage examples

Example

import

torch

Flip a 2D tensor upside down

x

=

torch.

arange

(

12

)

.

reshape

(

3

,

4

)

print

(

"Original tensor:"

)

print

(

x

)

result

=

torch.

flipud

(

x

)

print

(

"Flip upside down:"

)

print

(

result

)

Flip a square matrix upside down

y

=

torch.

tensor

(

[

[

1

,

2

,

3

]

,

[

4

,

5

,

6

]

,

[

7

,

8

,

9

]

]

)

print

(

"n3x3 square matrix:"

)

print

(

y

)

result

=

torch.

flipud

(

y

)

print

(

"Flip upside down:"

)

print

(

result

)

Flip a 1D tensor upside down

z

=

torch.

tensor

(

[

1

,

2

,

3

,

4

]

)

result

=

torch.

flipud

(

z

)

print

(

"n1D tensor [1, 2, 3, 4]:"

)

print

(

"Flip upside down:"

,

result

)

The output is:

原始张量:

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

        [ 4,  5,  6,  7],

        [ 8,  9, 10, 11]])

Vertical flip:

tensor([[ 8,  9, 10, 11],

        [ 4,  5,  6,  7],

        [ 0,  1,  2,  3]])



3x3 方阵:

tensor([[1, 2, 3],

        [4, 5, 6],

        [7, 8, 9]])

Vertical flip:

tensor([[7, 8, 9],

        [4, 5, 6],

        [1, 2, 3]])



一维张量 [1, 2, 3, 4]:

上下翻转: tensor([4, 3, 2, 1])


PyTorch torch reference manual PyTorch torch reference manual