- paddle. flip ( x, axis, name=None )
Reverse the order of a n-D tensor along given axis in axis.
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) – 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 .
Tensor or LoDTensor calculated by flip layer. The data type is same with input x.
- Return type
import paddle import numpy as np image_shape=(3, 2, 2) x = np.arange(image_shape * image_shape * image_shape).reshape(image_shape) x = x.astype('float32') img = paddle.to_tensor(x) out = paddle.flip(img, [0,1]) print(out) # [[[10,11][8, 9]],[[6, 7],[4, 5]] [[2, 3],[0, 1]]]