roll

paddle.fluid.layers.roll(input, shifts, dims=None)[source]

Roll the input tensor along the given dimension(s). Elements that are shifted beyond the last position are re-introduced at the first position. If a dimension is not specified, the tensor will be flattened before rolling and then restored to the original shape.

Parameters
  • input (Variable) – The input tensor variable.

  • shifts (int|list|tuple) – The number of places by which the elements of the input tensor are shifted.

  • dims (int|list|tuple|None) – Dimentions along which to roll.

Returns

A Tensor with same data type as input.

Return type

Variable

Examples

System Message: ERROR/3 (/usr/local/lib/python2.7/dist-packages/paddle/fluid/layers/nn.py:docstring of paddle.fluid.layers.roll, line 18)

Error in “code-block” directive: maximum 1 argument(s) allowed, 9 supplied.

.. code-block:: python
    import numpy as np
    import paddle.fluid as fluid

    data = np.array([[1.0, 2.0, 3.0],
                     [4.0, 5.0, 6.0],
                     [7.0, 8.0, 9.0]])
    with fluid.dygraph.guard():
        x = fluid.dygraph.to_variable(data)
        out_z1 = fluid.layers.roll(x, shifts=1)
        print(out_z1.numpy())
        #[[9. 1. 2.]
        # [3. 4. 5.]
        # [6. 7. 8.]]
        out_z2 = fluid.layers.roll(x, shifts=1, dims=0)
        print(out_z2.numpy())
        #[[7. 8. 9.]
        # [1. 2. 3.]
        # [4. 5. 6.]]