mindspore.ops.sort

查看源文件
mindspore.ops.sort(input_x, axis=- 1, descending=False)[源代码]

对输入tensor指定轴的元素进行排序。

说明

当前Ascend后端只支持对最后一维进行排序。

参数:
  • input_x (Tensor) - 输入tensor。

  • axis (int,可选) - 指定排序的轴,默认 -1 ,表示指定最后一维。

  • descending (bool,可选) - 排序方式。 True 表示按降序排列,否则按升序排列,默认 False

警告

目前能良好支持的数据类型有:float16、uint8、int8、int16、int32、int64。如果使用float32,可能产生精度误差。

返回:

一个由tensor组成的tuple(sorted_tensor, indices)

支持平台:

Ascend GPU CPU

样例:

>>> 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]]))