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

PyTorch torch.roll function

PyTorch torch.roll function


PyTorch torch reference manual PyTorch torch reference manual

torch.roll is a function in PyTorch used to roll tensor elements.

Function definition

torch.roll(input, shifts, dims)


Usage examples

Example

import

torch

x

=

torch.

arange

(

8

)

Roll forward by 2 positions

print

(

torch.

roll

(

x

,

2

)

)

Roll backward by 2 positions

print

(

torch.

roll

(

x

,

2

)

)

The output is:

tensor([6, 7, 0, 1, 2, 3, 4, 5])

tensor([2, 3, 4, 5, 6, 7, 0, 1])


PyTorch torch reference manual PyTorch torch reference manual