mindspore.mint.sort

View Source On AtomGit
mindspore.mint.sort(input, *, dim=- 1, descending=False, stable=False)[source]

Sort the elements of the input tensor along the given dimension.

Warning

Currently, the data types of mindspore.float16, mindspore.uint8, mindspore.int8, mindspore.int16, mindspore.int32, mindspore.int64 are well supported. If use mindspore.float32, it may cause loss of accuracy.

Parameters

input (Tensor) – The input tensor.

Keyword Arguments
  • dim (int, optional) – The dimension to sort along. Default -1, means the last dimension.

  • descending (bool, optional) – Controls the sort order. If descending is True, the elements are sorted in descending order, or else sorted in ascending order. Default False .

  • stable (bool, optional) – Whether to preserve the order of equivalent elements. Default False .

Returns

Tuple of two tensors, tuple(sorted_tensor, indices)

Raises

ValueError – If dim is not in range of [-len(input.shape), len(input.shape)).

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> x = mindspore.tensor([[8, 2, 1], [5, 9, 3], [4, 6, 7]], mindspore.float16)
>>> output = mindspore.mint.sort(x)
>>> # The output below is based on the Ascend platform.
>>> print(output)
(Tensor(shape=[3, 3], dtype=Float16, value=
[[ 1.0000e+00,  2.0000e+00,  8.0000e+00],
[ 3.0000e+00,  5.0000e+00,  9.0000e+00],
[ 4.0000e+00,  6.0000e+00,  7.0000e+00]]), Tensor(shape=[3, 3], dtype=Int64, value=
[[2, 1, 0],
[2, 0, 1],
[0, 1, 2]]))