mindspore.ops.roll
- mindspore.ops.roll(x, shifts, dims=None)[source]
Rolls the elements of a tensor along an axis.
- Parameters
x (Tensor) – Input tensor.
shifts (Union[list(int), tuple(int), int]) – Specifies the number of places by which elements are shifted positively (towards larger indices) along the specified dimension. Negative shifts will roll the elements in the opposite direction.
dims (Union[list(int), tuple(int), int], optional) – Specifies the dimension indexes of shape to be rolled. Default: None. If dims is None, the Tensor will be flattened before rolling and then restored to the original shape.
- Returns
Tensor, has the same shape and type as x.
- Raises
- Supported Platforms:
Ascend
GPU
Examples
>>> import numpy as np >>> import mindspore as ms >>> import mindspore.ops as ops >>> from mindspore import Tensor >>> input_x = Tensor(np.array([0, 1, 2, 3, 4]).astype(np.float32)) >>> output = ops.roll(input_x, shifts=2, dims=0) >>> print(output) [3. 4. 0. 1. 2.]