Find whether a numpy array is a subset of a larger array in Python
Question: I have 2 arrays, for the sake of simplicity let's say the original one is a
random set of numbers:

    
    
    import numpy as np
    a=np.random.rand(N)
    

Then I sample and shuffle a subset from this array:

    
    
    b=np.array()  <------size<N
    

The shuffling I do do not store the index values, so b is an unordered subset
of a

Is there an easy way to get the original indexes of b, so they are in the same
order as a, say, if element 2 of b has the index 4 in a, create an array of
its assignation.

I could use a for cycle checking element by element, but perhaps there is a
more pythonic way

Thanks


Answer: I think the most computationally efficient thing to do is to keep track of the
indices that associate `b` with `a` as `b` is created.

For example, instead of sampling `a`, sample the indices of `a`:

    
    
    indices = random.sample(range(len(a)), k)   # k < N
    b = a[indices]
    

