[Numpy-discussion] Should dot return 1x1 matrix as scalar?
Travis Oliphant
oliphant.travis at ieee.org
Fri Jan 13 20:41:02 CST 2006
Paulo J. S. Silva wrote:
>Numpy:
>
>In [27]:i = time.clock(); bench(A,b); time.clock() - i
>Out[27]:10.610000000000014
>
>
>Why is numpy so slow??????
>
>
>
I think the problem here is that using the properties here to take
advantage of the nice matrix math stuff is slower than just computing
the dot product in the fastest possible way with raw arrays. I've been
concerned about this for awhile. The benchmark below makes my point.
While a matrix is a nice thing, I think it will always be slower.... It
might be possible to speed it up and I'm open to suggestions...
To see what I mean, try this....
import timeit
t1 = timeit.Timer('c = b.T*A; d=c*b','from numpy import rand,mat; A =
mat(rand(1000,1000));b = mat(rand(1000,1))')
t2 = timeit.Timer('c = dot(b,A); d=dot(b,c)','from numpy import rand,
dot; A = rand(1000,1000);b = rand(1000)')
>>> t1.timeit(100)
6.0398328304290771
>>> t2.timeit(100)
1.2430641651153564
So, using raw arrays and dot product is 5x faster in this case.....
-Travis
More information about the Numpy-discussion
mailing list