Python | Numpy matrix.argsort()

With the help of Numpy matrix.argmax() method, we are able to find the sort the elements in the given matrix having one or more dimension and it would return the index value of sorted elements.

Syntax : matrix.argsort()

Return : Return index number of sorted elements in matrix



Example #1 :
In this example we can see that with the help of matrix.argsort() method, we are able to find the sorted element in a given matrix and gives output as index of sorted array.

filter_none

edit
close

play_arrow

link
brightness_4
code

# import the important module in python
import numpy as np
           
# make a matrix with numpy
gfg = np.matrix('[1, -2, 3, -4]')
           
# applying matrix.argsort() method
geeks = gfg.argsort()
     
print(geeks)

chevron_right


Output:

[[3 1 0 2]]

Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# import the important module in python
import numpy as np
           
# make a matrix with numpy
gfg = np.matrix('[-1, 2, 3; 4, -5, 6; 7, -8, 9]')
           
# applying matrix.argsort() method
geeks = gfg.argsort()
     
print(geeks)

chevron_right


Output:

[[0 1 2]
 [1 0 2]
 [1 0 2]]


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.