# argsort¶

paddle. argsort ( x, axis=- 1, descending=False, name=None ) [source]

Sorts the input along the given axis, and returns the corresponding index tensor for the sorted output values. The default sort algorithm is ascending, if you want the sort algorithm to be descending, you must set the `descending` as True.

Parameters
• x (Tensor) – An input N-D Tensor with type float32, float64, int16, int32, int64, uint8.

• axis (int, optional) – Axis to compute indices along. The effective range is [-R, R), where R is Rank(x). when axis<0, it works the same way as axis+R. Default is -1.

• descending (bool, optional) – Descending is a flag, if set to true, algorithm will sort by descending order, else sort by ascending order. Default is false.

• name (str, optional) – For details, please refer to Name. Generally, no setting is required. Default: None.

Returns

sorted indices(with the same shape as `x` and with data type int64).

Return type

Tensor

Examples

```import paddle

[0,0,1,7],
[6,9,2,4]],
[[5,2,4,2],
[4,7,7,9],
[1,7,0,6]]],
dtype='float32')
out1 = paddle.argsort(x, axis=-1)
out2 = paddle.argsort(x, axis=0)
out3 = paddle.argsort(x, axis=1)

print(out1)
#[[[0 3 1 2]
#  [0 1 2 3]
#  [2 3 0 1]]
# [[1 3 2 0]
#  [0 1 2 3]
#  [2 0 3 1]]]

print(out2)
#[[[0 1 1 1]
#  [0 0 0 0]
#  [1 1 1 0]]
# [[1 0 0 0]
#  [1 1 1 1]
#  [0 0 0 1]]]

print(out3)
#[[[1 1 1 2]
#  [0 0 2 0]
#  [2 2 0 1]]
# [[2 0 2 0]
#  [1 1 0 2]
#  [0 2 1 1]]]
```