Skip to content
Advertisement

Can I sort two related arrays in parallel using python?

I have two NumPy arrays with the shape (74395, 1) storing float values where arr1[0] correlates to arr2[0] and so on. I would like to sort them together in ascending order by the values stored in the second array.

As an example:

JavaScript

wanted result:

JavaScript

How could I do that in python?

Advertisement

Answer

Use numpy.argsort with numpy.take_along_axis:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement