mindspore.ops.reverse

View Source On Gitee
mindspore.ops.reverse(x, axis)[source]

Reverses specific dimensions of a tensor.

Warning

The value range of “axis” is [-dims, dims - 1]. “dims” is the dimension length of “input_x”.

Parameters
  • x (Tensor) – The target tensor. The shape is \((N, *)\) where \(*\) means, any number of additional dimensions.

  • axis (Union[tuple(int), list(int)]) – The indices of the dimensions to reverse.

Outputs:

Tensor, has the same shape and type as x.

Raises
  • TypeError – If axis is neither list nor tuple.

  • TypeError – If element of axis is not an int.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> input_x = Tensor(np.array([[1, 2, 3, 4], [5, 6, 7, 8]]), mindspore.int32)
>>> output = ops.reverse(input_x, axis=[1])
>>> print(output)
[[4 3 2 1]
 [8 7 6 5]]
>>> input_x = Tensor(np.array([[1, 2, 3, 4], [5, 6, 7, 8]]), mindspore.int32)
>>> output = ops.reverse(input_x, axis=[1, 0])
>>> print(output)
[[8 7 6 5]
 [4 3 2 1]]