flip¶
-
paddle.fluid.layers.
flip
(input, dims, name=None)[source] Reverse the order of a n-D tensor along given axis in dims.
- Parameters
input (Variable) – A Tensor(or LoDTensor) with shape \([N_1, N_2,..., N_k]\) . The data type of the input Tensor should be float32, float64, int32, int64, bool.
dims (list) – The axis to flip on.
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.
- Return type
Variable
Examples
import paddle.fluid as fluid import numpy as np input = fluid.data(name="x", shape=[-1, 2, 2], dtype='float32') output = fluid.layers.flip(input, dims=[0, 1]) exe = fluid.Executor(fluid.CPUPlace()) exe.run(fluid.default_startup_program()) img = np.arange(12).reshape((3,2,2)).astype(np.float32) res = exe.run(fluid.default_main_program(), feed={'x':img}, fetch_list=[output]) print(res) # [[[10,11][8, 9]],[[6, 7],[4, 5]] [[2, 3],[0, 1]]]