0

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'])
6
  • What is the issue? Where are you using a_sorted? Are you getting an error? Commented Jan 2, 2024 at 3:54
  • @jared b comes out as sorted independently. Not as per a_sorted masked. Commented Jan 2, 2024 at 3:58
  • 1
    What you expect is not really clear. What is the relation between a, a_sorted, b and b_sorted? Commented Jan 2, 2024 at 4:02
  • Is a_sorted the result of a[np.argsort(a)]? Commented Jan 2, 2024 at 4:03
  • 1
    The mask of a_sorted is [0, 1, 2, 3, 4] so the result of b[np.argsort(a_sorted)] gives the same output as b. Commented Jan 2, 2024 at 4:07

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.