Reputation: 160
The numpy arrays symbols and ocurrence both have the same size/len.
bidimentional_array = np.array([symbols,occurrence])
What I want is, do a descending sort in ocurrence and make it so that symbols index will change in function of the sort. What's the most effective way?
Upvotes: 1
Views: 88
Reputation: 58975
Use np.argsort
to obtain the sorting indices according to the second column and fancy indexing to obtain the sorted array:
bidimentional_array = bidimentional_array[np.argsort(bidimentional_array[:,1])]
To reverse the sorted array:
bidimentional_array = bidimentional_array[::-1]
Upvotes: 1