Skip to content
Advertisement

Reordering a list based on another list in Python

I have two lists Ii0 and Iv0 containing numpy arrays. I am using argsort() to reorder elements in Ii0 to generate a new list Ii01. I want to use the same order to reorder elements in Iv0 to generate a new list Iv01. I present the current and expected output.

JavaScript

The current output is

JavaScript

The expected output is

JavaScript

Advertisement

Answer

Use:

JavaScript

Output

JavaScript

Or as an alternative, use np.take_along_axis:

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