flip

paddle. flip ( x, axis, name=None ) [source]

Reverse the order of a n-D tensor along given axis in axis.

Parameters
  • x (Tensor) – A Tensor(or LoDTensor) with shape \([N_1, N_2,..., N_k]\) . The data type of the input Tensor x should be float32, float64, int32, int64, bool.

  • axis (list|tuple|int) – The axis(axes) to flip on. Negative indices for indexing from the end are accepted.

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name .

Returns

Tensor or LoDTensor calculated by flip layer. The data type is same with input x.

Return type

Tensor

Examples

import paddle
import numpy as np

image_shape=(3, 2, 2)
x = np.arange(image_shape[0] * image_shape[1] * image_shape[2]).reshape(image_shape)
x = x.astype('float32')
img = paddle.to_tensor(x)
tmp = paddle.flip(img, [0,1])
print(tmp) # [[[10,11],[8, 9]], [[6, 7],[4, 5]], [[2, 3],[0, 1]]]

out = paddle.flip(tmp,-1)
print(out) # [[[11,10],[9, 8]], [[7, 6],[5, 4]], [[3, 2],[1, 0]]]