reverse

paddle.fluid.layers.reverse(x, axis)[source]

The OP reverses the tensor x along the given axis.

Parameters
  • x (Variable) – A tensor to be reversed, its data type supports bool, float32, float64, int32, int64 and uint8.

  • axis (int|tuple|list) – A dimension or a set of dimensions of x to reverse. Must be in the range [-rank( x ), rank( x )). If it is a tuple or a list, reversing will be apply on each axis in the tuple or list.

Returns

The reversed tensor with the same shape and data type as x.

Return type

Variable

Examples

import paddle.fluid as fluid
import numpy as np
data = fluid.layers.assign(np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype='float32')) # [[0., 1., 2.], [3., 4., 5.], [6., 7., 8.]]
result1 = fluid.layers.reverse(data, 0) # [[6., 7., 8.], [3., 4., 5.], [0., 1., 2.]]
result2 = fluid.layers.reverse(data, [0, 1]) # [[8., 7., 6.], [5., 4., 3.], [2., 1., 0.]]