flip(input, dims) → Tensor¶
Reverse the order of a n-D tensor along given axis in dims.
flow.flip makes a copy of
input’s data. This is different from NumPy’s np.flip, which returns a view in constant time. Since copying a tensor’s data is more work than viewing that data, flow.flip is expected to be slower than np.flip.
input (Tensor) – the input tensor
dims (a list or tuple) – axis to flip on
>>> import oneflow as flow >>> import numpy as np >>> np_arr = np.arange(0, 8).reshape((2, 2, 2)).astype(np.float32) >>> input = flow.Tensor(np_arr) >>> input.shape oneflow.Size([2, 2, 2]) >>> out = flow.flip(input, [0, 1]) >>> out tensor([[[6., 7.], [4., 5.]], [[2., 3.], [0., 1.]]], dtype=oneflow.float32)