I have 2 numpy array
s of different sizes. Theoretically, the one will be a subset of the other. I want to find the indexes in the larger numpy array
where its values match with the smaller subset.
For e.g
A = [ 7.52 8.32 16.96 20.05 -24.96 -42.69 -47.47 55.04 -57.62 2.03
61.94 64.41 -71.3 93.6 151.65 151.75 -0.43 -3.18 4.59 -5.55
6.44 -9.48 9.31 0.67 -14.34 -8.09 16.23 17.69 19.46 23.52
-52.59]
B = [61.94 16.23 19.46 -5.55 -0.43 93.6]
2 for
loops will do the deed, but I want to know if there is a python way to do this faster.
I tried with one loop but it does not work ( I suspect the numpy.where
does not work with different size array)
def get_index(self, lst_1, lst_2):
tmp_list = list()
for i in range(min(len(lst_1), len(lst_2))):
if np.where(lst_2[i] == lst_1):
tmp_list.append(i)
return tmp_list
Any suggestions will be appreciated :)
Thank you