megengine.functional.sort#

sort(inp, descending=False)[source]#

Returns sorted tensor and the indices would sort the input tensor.

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

  • descending (bool) – sort in descending order, where the largest comes first. Default: False

Return type:

Tuple[Tensor, Tensor]

Returns:

tuple of two tensors (sorted_tensor, indices_of_int32).

Examples

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