I try to sort an array:
import numpy as np
arr = [5,3,7,2,6,34,46,344,545,32,5,22]
print "unsorted"
print arr
np.argsort(arr)
print "sorted"
print arr
But the output is:
unsorted
[5, 3, 7, 2, 6, 34, 46, 344, 545, 32, 5, 22]
sorted
[5, 3, 7, 2, 6, 34, 46, 344, 545, 32, 5, 22]
The array does not change at all
np.argsort
doesn't sort the list in place, it returns a list full of indicies that you are able to use to sort the list.
You must assign this returned list to a value:
new_arr = np.argsort(arr)
Then, to sort the list with such indices, you can do:
np.array(arr)[new_arr]
Try
order = np.argsort(arr)
print np.array(arr)[order]
the argsort response is the index of the elements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With