I am trying to do these steps in NumPy. It was easy to do this with python list sort(), and argsort().
How do I do this in Numpy?
a = np.array([10,30,20,40,50])
a_sorted = np.array([10,20,30,40,50])
Get mask of a_sorted
b = np.array(['one','three','two','four','five'])
Apply the mask to b
Expected array sorted according to a_sorted:
b_sorted = np.array(['one','two','three','four','five'])
a_sorted? Are you getting an error?a,a_sorted,bandb_sorted?a_sortedthe result ofa[np.argsort(a)]?a_sortedis [0, 1, 2, 3, 4] so the result ofb[np.argsort(a_sorted)]gives the same output asb.