Reputation: 671
So I have an 2d array where the first column consists of floats ranging between -1.0
and 1.0
. I want to sort the array based on the first column, from lowest to highest, this way:
data[0,data[0,:].argsort()]
But the problem is that the negative values are sorted from highest to lowest value, so -0.26
comes before -0.56
, while the positive values are sorted from lowest to highest, 0.26
before 0.56
for example.
Why is this happening and how can I get the correct results, that is that also the negative values are listed from lowest to largest value?
Upvotes: 2
Views: 1979
Reputation: 97331
Your array is a string array, so you need to convert it to float array first:
data = data.astype(float)
data[0,data[0,:].argsort()]
Upvotes: 3