From: Francesc A. <fa...@ca...> - 2006-08-26 21:22:42
|
A Dissabte 26 Agost 2006 12:26, Travis Oliphant va escriure: > If frameis is 1-D, then you should be able to use > > temp =3D data.take(frameis,axis=3D0) > > for the first step. This can be quite a bit faster (and is a big > reason why take is still around). There are several reasons for this > (one of which is that index checking is done over the entire list when > using indexing). Well, some days ago I've stumbled on this as well. NumPy manual says=20 that .take() is usually faster than fancy indexing, but my timings shows th= at=20 this is no longer true in recent versions of NumPy: In [56]: Timer("b.take(a)","import numpy; a=3Dnumpy.arange(999,-1,-1,=20 dtype=3D'l');b=3Da[:]").repeat(3,1000) Out[56]: [0.28740906715393066, 0.20345211029052734, 0.20371079444885254] In [57]: Timer("b[a]","import numpy; a=3Dnumpy.arange(999,-1,-1,=20 dtype=3D'l');b=3Da[:]").repeat(3,1000) Out[57]: [0.20807695388793945, 0.11684703826904297, 0.11686491966247559] I've done some profiling on this and it seems that take is using C memmove= =20 call so as to copy the data, and this is *very* slow, at least in my platfo= rm=20 (Linux on Intel). On its hand, fancy indexing seems to use an iterator and= =20 copying the elements one-by-one seems faster. I'd say that replacing memmov= e=20 by memcpy would make .take() much faster. Regards, =2D-=20 >0,0< Francesc Altet =A0 =A0 http://www.carabos.com/ V V C=E1rabos Coop. V. =A0=A0Enjoy Data "-" |