Determine the shuffled indices of two lists/arrays

后端 未结 6 593
野的像风
野的像风 2021-01-18 16:03

As a challenge, I\'ve given myself this problem:

Given 2 lists, A, and B, where B is a shuffled version of A, the idea is to figure out the shuffled indices.

6条回答
  •  鱼传尺愫
    2021-01-18 16:23

    The numpy_indexed package has an efficient and general solution to this:

    import numpy_indexed as npi
    result = npi.indices(A, B)
    

    Note that it has a kwarg to set a mode for dealing with missing values; and it works with nd-arrays of any type just the same, as it does with 1d integer arrays.

提交回复
热议问题