roll
- paddle. roll ( x: Tensor, shifts: int | Sequence[int], axis: int | Sequence[int] | None = None, name: str | None = None ) Tensor [source]
-
Roll the x tensor along the given axis(axes). With specific ‘shifts’, Elements that roll beyond the last position are re-introduced at the first according to ‘shifts’. If a axis is not specified, the tensor will be flattened before rolling and then restored to the original shape.
Note
Alias Support: The parameter name
input
can be used as an alias forx
, and the parameter namedim
can be used as an alias foraxis
. For example,roll(input=tensor_x, dim=1)
is equivalent toroll(x=tensor_x, axis=1)
.- Parameters
-
x (Tensor) – The x tensor as input. alias:
input
.shifts (int|list|tuple) – The number of places by which the elements of the x tensor are shifted.
axis (int|list|tuple, optional) – axis(axes) along which to roll. Default: None alias:
dim
.name (str|None, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to api_guide_Name .
The image below shows a 2D tensor [[1,2,3],[4,5,6],[7,8,9]] being transformed into tensors with different shapes through the roll operation. .. image:: https://githubraw.cdn.bcebos.com/PaddlePaddle/docs/develop/docs/images/api_legend/roll.png
- width
-
700
- align
-
center
- alt
-
legend of roll API
- Returns
-
Tensor, A Tensor with same data type as x.
Examples