0

I have a numpy array that is equivalent to:

array([[51, 62, 23],
       [24, 45, 16],
       [67, 78, 39]])

Just much bigger. I'm trying to sort by the second column (ie. the number 62, 45, 78) but keep the horizontal elements together. The output I'm trying to get would be:

array([[24, 45, 16],
       [51, 62, 23],
       [67, 78, 39]])

I can't figure out how to do this with np.sort - I don't think this is the correct function for the job (although I'm a bit new to numpy so I might be wrong) - I'm happy to learn a new function, code snippets would be great, but a simple 'use np.blah' would suffice :D

FraserOfSmeg
  • 1,128
  • 2
  • 23
  • 41

1 Answers1

1

If your numpy array is arr, this should work: arr[arr[:,1].argsort()]

Josh
  • 50
  • 9