megengine.functional.sort#

sort(inp, descending=False)[源代码]#

返回经过排序后的张量,以及对应原始张量中的索引位置。

参数:
  • inp (Tensor) – input tensor. If it’s 2d, the result would be sorted by row.

  • descending (bool) – 降序排列,即最大值位于第一位置。 默认:False

返回类型:

Tuple[Tensor, Tensor]

返回:

由两个张量组成的元组 (sorted_tensor, indices_of_int32)

实际案例

>>> import numpy as np
>>> x = Tensor(np.array([1,2], dtype=np.float32))
>>> out, indices = F.sort(x)
>>> out.numpy()
array([1., 2.], dtype=float32)