argsort¶
- paddle. argsort ( x, axis=- 1, descending=False, name=None ) [source]
-
This OP 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 0.
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) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.
- Returns
-
sorted indices(with the same shape as
x
and with data type int64). - Return type
-
Tensor
Examples
import paddle x = paddle.to_tensor([[[5,8,9,5], [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=x, axis=-1) out2 = paddle.argsort(x=x, axis=0) out3 = paddle.argsort(x=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]]]