looping and searching in numpy array

Mark Lawrence breamoreboy at yahoo.co.uk
Thu Mar 10 08:22:14 EST 2016


On 10/03/2016 11:43, Heli wrote:
> 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.
>
>
> for id in np.nditer(npArray1):
>
>         newId=(np.where(npArray2==id))[0][0]
>
>
> Is there anyway I can make the above faster? 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,
>

I'm no numpy expert, but if you're using a loop my guess is that you're 
doing it wrong.  I suggest your first port of call is the numpy docs if 
you haven't all ready been there, then the specific numpy mailing list 
or stackoverflow, as it seems very likely that this type of question has 
been asked before.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




More information about the Python-list mailing list