mindspore.ops.flip

mindspore.ops.flip(x, dims)[source]

Reverses the order of elements in a tensor along the given axis.

The shape of the tensor is preserved, but the elements are reordered.

Parameters
  • x (Tensor) – Input tensor.

  • dims (Union[list[int], tuple[int]]) – Axis or axes along which to flip over. Flipping is performed on all of the axes specified in the tuple, If dims is a tuple of integers contains negative, it counts from the last to the first axis.

Returns

Tensor, with the entries of dims reversed.

Raises
Supported Platforms:

GPU CPU

Examples

>>> import mindspore as ms
>>> import mindspore.ops as ops
>>> import numpy as np
>>> x = ms.Tensor(np.arange(8).reshape((2, 2, 2)))
>>> output = ops.flip(x, (0, 2))
>>> print(output)
[[[5. 4.]
[7. 6.]]
[[1. 0.]
[3. 2.]]]