mindspore.ops.flip

View Source On Gitee
mindspore.ops.flip(input, 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
  • input (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:

Ascend GPU CPU

Examples

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