sort

dragon.sort(
  inputs,
  axis=- 1,
  descending=False,
  **kwargs
)[source]

Return the sorted elements along the given axis.

By default, the last axis is chosen:

x = dragon.constant([[1, 2, 3], [3, 2, 1]])
value1, index1 = dragon.sort(x)
value2, index2 = dragon.sort(x, axis=1)  # Equivalent

Sort in the inverse order if descending is True:

x = dragon.constant([1, 2, 3])
_, index1 = dragon.sort(-x)
_, index2 = dragon.sort(x, descending=True)  # Equivalent
Parameters:
  • inputs (dragon.Tensor) – The input tensor.
  • axis (int, optional, default=-1) – The axis to sort elements.
  • descending (bool, optional, default=False) – Sort in the descending order or not.
Returns:

Sequence[dragon.Tensor] – The value and index tensor.