msort

paddle. msort ( input: Tensor, *, out: Tensor | None = None ) [源代码]

沿输入 Tensor 的第 0 轴(axis=0)按升序对元素进行排序。

该函数等价于 paddle.sort(x, axis=0)

参数

  • input (Tensor) - 输入的 N-D Tensor,支持的数据类型为:float32、float64、int16、int32、int64、uint8。别名 input

  • name (str,可选) - 具体用法请参见 api_guide_Name,一般无需设置,默认值为 None。

关键字参数

  • out (Tensor,可选) - 输出 Tensor,若不为 None,计算结果将保存在该 Tensor 中,默认值为 None

返回

Tensor,排序后的输出(与 input 维度相同、数据类型相同)。

代码示例

>>> import paddle

>>> x = paddle.to_tensor([[[5,8,9,5],
...                        [0,0,1,7],
...                        [6,9,2,4]],
...                       [[5,2,4,2],
...                        [4,7,7,9],
...                        [1,7,0,6]]],
...                      dtype='float32')
>>> out1 = paddle.msort(input=x)
>>> print(out1.numpy())
[[[5. 2. 4. 2.]
  [0. 0. 1. 7.]
  [1. 7. 0. 4.]]
 [[5. 8. 9. 5.]
  [4. 7. 7. 9.]
  [6. 9. 2. 6.]]]

>>> out2 = paddle.empty_like(x)
>>> paddle.msort(input=x, out=out2)
>>> print(out2.numpy())
[[[5. 2. 4. 2.]
  [0. 0. 1. 7.]
  [1. 7. 0. 4.]]
 [[5. 8. 9. 5.]
  [4. 7. 7. 9.]
  [6. 9. 2. 6.]]]