mindspore.numpy.flip

mindspore.numpy.flip(m, axis=None)[source]

Reverses the order of elements in an array along the given axis.

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

Note

On CPU, the supported dtypes are np.float16, np.float32, and np.float64.

Parameters
  • m (Tensor) – Input array.

  • axis (None or int or tuple of ints, optional) – Axis or axes along which to flip over. The default, axis=None, will flip over all of the axes of the input array. If axis is negative it counts from the last to the first axis. If axis is a tuple of ints, flipping is performed on all of the axes specified in the tuple.

Returns

Tensor, with the entries of axis reversed.

Raises

TypeError – if the input is not a tensor.

Supported Platforms:

GPU

Example

>>> import mindspore.numpy as np
>>> A = np.arange(8.0).reshape((2,2,2))
>>> output = np.flip(A)
>>> print(output)
[[[7, 6],
[5, 4]],
[[3, 2],
[1, 0]]]
>>> output = np.flip(A, (0, 2))
>>> print(output)
[[[5, 4],
[7, 6]],
[[1, 0],
[3, 2]]]