[Numpy-discussion] Lookup array

Andrey N. Sobolev inconnu at list.ru
Tue Oct 11 03:39:05 EDT 2011


В Mon, 10 Oct 2011 11:20:08 -0400
Olivier Delalleau <shish at keba.be> пишет:

> 
> The following doesn't use numpy but seems to be about 20x faster:
> 
>     A_rows = {}
>     for i, row in enumerate(A):
>         A_rows[tuple(row)] = i
>     for i, row in enumerate(B):
>         C[i] = A_rows.get(tuple(row), -1)
> 
> -=- Olivier

Thanks a lot, Olivier, that's makes my program like 3x faster. 
One lesson I can draw from this - don't try to use NumPy in 
situations it doesn't fit :)

WBR,
Andrey


-- 
Researcher,
General and theoretical physics dept., South Ural State University
454080, Pr. Lenina, 76, Chelyabinsk, Russia
Tel: +7 351 265-47-13
andrey at physics.susu.ac.ru



More information about the NumPy-Discussion mailing list