mindspore.ops.argsort

mindspore.ops.argsort(input, axis=- 1, descending=False)[source]

Sorts the input tensor along the given dimension in specified order and return the sorted indices.

Parameters
  • input (Tensor) – The input tensor to sort.

  • axis (int) – The axis to sort along. Default: -1 , means the last dimension. The Ascend backend only supports sorting the last dimension.

  • descending (bool) – The sort order. If descending is True then the elements are sorted in descending order by value. Otherwise sort in ascending order. Default: False .

Returns

Tensor, the indices of sorted input tensor. Data type is int32.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> x = Tensor(np.array([[8, 2, 1], [5, 9, 3], [4, 6, 7]]), mindspore.float16)
>>> sort = ops.argsort(x)
>>> print(sort)
[[2 1 0]
 [2 0 1]
 [0 1 2]]