megengine.functional.argsort

argsort(inp, descending=False)[source]

Returns the indices that would sort the input tensor.

Parameters
  • inp (Tensor) – input tensor. If it’s 2d, the result would be array of indices show how to sort each row in the input tensor.

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

  • inp – Tensor:

  • descending – bool:

Return type

Tensor

Returns

indices of int32 indicates how to sort the input.

Examples

>>> import numpy as np
>>> x = Tensor(np.array([1,2], dtype=np.float32))
>>> F.argsort(x)
Tensor([0 1], dtype=int32, device=xpux:0)