I have a 2D array of "neighbors", and I want to re-order each row according to a corresponding row in another matrix (called "radii"). The below code works, but it uses a for loop over a numpy array, which I know is the incorrect way to do it. What is the correct numpy / broadcast solution to this re-ordering?
neighbors = np.array([[8,7,6], [3,2,1]])
radii = np.array([[0.4, 0.2, 0.1], [0.3, 0.9, 0.1]])
order = radii.argsort(axis=1)
for i in range(2):
neighbors[i] = neighbors[i,order[i]]
print(neighbors)
# Result:
[[6 7 8]
[1 3 2]]