[Numpy-discussion] Sum, multiply are slow ?

dmitrey openopt@ukr....
Thu Jul 12 00:48:55 CDT 2007


very interesting, however, it would be better if you provide exact code.
I didn't use timeit and I have some troubles with the module.

Regards, D.

David Cournapeau wrote:
> Hi,
>    
>     While profiling some code, I noticed that sum in numpy is kind of 
> slow once you use axis argument:
>
> import numpy as N
> a = N.random.randn(1e5, 30)
> %timeit N.sum(a) #-> 26.8ms
> %timeit N.sum(a, 1) #-> 65.5ms
> %timeit N.sum(a, 0) #-> 141ms
>
> Now, if I use some tricks, I get:
>
> %timeit N.sum(a) #-> 26.8 ms
> %timeit N.dot(a, N.ones(a.shape[1], a.dtype)) #-> 11.3ms
> %timeit N.dot(N.ones((1, a.shape[0]), a.dtype), a) #-> 15.5ms
>
> I realize that dot uses optimized libraries (atlas in my case) and all, 
> but is there any way to improve this situation ?
>
> Cheers,
>
> David
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
>
>   



More information about the Numpy-discussion mailing list