mindspore.ops.sort
- mindspore.ops.sort(input_x, axis=- 1, descending=False)[source]
Sort the elements of the input tensor along the given axis.
Warning
Non-backward-compatible change after version 2.9.0:
axiswill be renamed todim, and a newstableparameter will be added.Currently, the data types of float16, uint8, int8, int16, int32, int64 are well supported. If using float32, it may cause loss of accuracy.
Note
The Ascend backend only supports sorting the last dimension.
- Parameters
- Returns
Tuple(sorted_tensor, indices) of 2 tensors.
- Supported Platforms:
AscendGPUCPU
Examples
>>> import mindspore >>> x = mindspore.tensor([[8, 2, 1], [5, 9, 3], [4, 6, 7]], mindspore.float16) >>> output = mindspore.ops.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=Int32, value= [[2, 1, 0], [2, 0, 1], [0, 1, 2]]))