oneflow.argsort¶
-
oneflow.
argsort
() → Tensor¶ This operator sorts the input Tensor at specified dim and returns the indices of the sorted Tensor.
- Parameters
input (oneflow.Tensor) – the input Tensor.
dim (int, optional) – the dimension to be sorted. Defaults to the last dim (-1).
descending (bool, optional) – controls the sorting order (ascending or descending).
- Returns
The indices of the sorted Tensor.
- Return type
For example:
>>> import numpy as np >>> import oneflow as flow >>> x = np.array([[10, 2, 9, 3, 7], ... [1, 9, 4, 3, 2]]).astype("float32") >>> input = flow.Tensor(x) >>> output = flow.argsort(input) >>> output tensor([[1, 3, 4, 2, 0], [0, 4, 3, 2, 1]], dtype=oneflow.int32) >>> output = flow.argsort(input, descending=True) >>> output tensor([[0, 2, 4, 3, 1], [1, 2, 3, 4, 0]], dtype=oneflow.int32) >>> output = flow.argsort(input, dim=0) >>> output tensor([[1, 0, 1, 0, 1], [0, 1, 0, 1, 0]], dtype=oneflow.int32)