[Numpy-discussion] Should dot return 1x1 matrix as scalar?
oliphant.travis at ieee.org
Fri Jan 13 20:41:02 CST 2006
Paulo J. S. Silva wrote:
>In :i = time.clock(); bench(A,b); time.clock() - i
>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....
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)')
So, using raw arrays and dot product is 5x faster in this case.....
More information about the Numpy-discussion