mindspore.mint.roll

View Source On Gitee
mindspore.mint.roll(input, shifts, dims=None)[source]

Roll the elements of a tensor along a dimension.

Parameters
  • input (Tensor) – The input tensor.

  • shifts (Union[list(int), tuple(int), int]) – The amount of element shifting.

  • dims (Union[list(int), tuple(int), int], optional) – Specify the dimension to move. Default None , which means the input tensor will be flattened before computation, and the result will be reshaped back to the original input shape.

Returns

Tensor

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> input = mindspore.tensor([0, 1, 2, 3, 4], mindspore.float32)
>>> # case1: Parameter `shifts` is positive
>>> output = mindspore.mint.roll(input, shifts=2, dims=0)
>>> print(output)
[3. 4. 0. 1. 2.]
>>> # case2: Parameter `shifts` is negative
>>> output = mindspore.mint.roll(input, shifts=-2, dims=0)
>>> print(output)
[2. 3. 4. 0. 1.]