Rayden
Rayden

Reputation: 160

Sort bidimentional numpy array

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

Answers (1)

Saullo G. P. Castro
Saullo G. P. Castro

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

Related Questions