I have a fairly simple question about how to sort an entire array/recarray by a given column. For example, given the array:
import numpy as np
data = np.a
Here's an extension that works with slices:
import numpy as np
x = np.array([[9, 1, 2],
[5, 3, 4],
[0, 5, 6]])
Sorting by rows:
x[:, x[1,:].argsort()] # Sort by second row
array([[1, 2, 9]
[3, 4, 5]
[5, 6, 0]])
Sorting by columns:
x[x[:,0].argsort(), :] # Sort by first column
array([[0, 5, 6],
[5, 3, 4],
[9, 1, 2]])