Hi all,

I have 2 arrays - A with the dimensions of 1000x4 and B with the
dimensions of 5000x4. B doesn't (hopefully) contain any rows that are
not in A. I need to create a lookup array C, the i-th value of which
will be the index of B[i] in A. In the (very rare) case when B[i] is not
in A C[i] should be equal to -1. Now I'm dealing with it using which:
...
import numpy as np
for i, row in enumerate(B):
    try:
        C[i] = np.which(np.all(A == row, axis = 1))[0][0]
    except (IndexError, ):
        C[i] = -1
...
but that's very slow (it consumes 70% of cpu time needed by the whole
program). I guess that it's because of a slow pythonic loop, but I
just can't get how to get rid of it. Any suggestions would be
appreciated.

Thanks in advance,
Andrey



-- 
Researcher,
General and theoretical physics dept., South Ural State University
454080, Pr. Lenina, 76, Chelyabinsk, Russia
Tel: +7 351 265-47-13
and...@physics.susu.ac.ru
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to