[Numpy-discussion] Fwd: Looping and searching in numpy array

Hedieh Ebrahimi hemla21 at gmail.com
Thu Mar 10 12:00:53 EST 2016


Dear all,

I need to loop over a numpy array and then do the following search. The
following is taking almost 60(s) for an array (npArray1 and npArray2 in the
example below) with around 300K values.

In other words, I am  looking for the index of the first occurence in
npArray2
for every value of npArray1.


for id in np.nditer(npArray1):

       newId=(np.where(npArray2==id))[0][0]


Is there anyway I can make the above faster using numpy? I need to run the
script above on much bigger arrays (50M). Please note that my two numpy
arrays in the lines above, npArray1 and npArray2  are not necessarily the
same size, but they are both 1d.


Thanks a lot for your help,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20160310/64a076e7/attachment.html>


More information about the NumPy-Discussion mailing list