Skip to content Skip to sidebar Skip to footer

Sort Numpy Array By Row And Order Matching Values Based On Original Array

I have a 2D numpy array and I would like to sort the rows based on first column values. The trouble is the way it is formatted: Column I am sorting by: 0,1,2,3,4,0,1,2,3,4,0,1,2,3,

Solution 1:

You can change the sorting algorithm used by argsort with the kind argument.

Use

sortedData= myData[myData[:,0].argsort(kind='mergesort')]

to preserve the order of the equal items. (Merge sort is a stable sorting algorithm.)

Post a Comment for "Sort Numpy Array By Row And Order Matching Values Based On Original Array"