[Numpy-discussion] matrix multiplication

Keith Goodman kwgoodman@gmail....
Fri Jun 5 17:54:20 CDT 2009


On Fri, Jun 5, 2009 at 3:02 PM, Alan G Isaac <aisaac@american.edu> wrote:
> I think something close to this would be possible:
> add dot as an array method.
>        A .dot(B) .dot(C)
> is not as pretty as
>        A * B * C
> but it is much better than
>        np.dot(np.dot(A,B),C)

I've noticed that x.sum() is faster than sum(x)

>> x = np.array([1,2,3])
>> timeit x.sum()
100000 loops, best of 3: 3.01 µs per loop
>> from numpy import sum
>> timeit sum(x)
100000 loops, best of 3: 4.84 µs per loop

Would the same be true of dot? That is, would x.dot(y) be faster than
dot(x,y)? Or is it just that np.sum() has to go through some extra
python code before it hits the C code?

In general, if I'm trying to speed up an inner loop, I try to replace
func(x) with x.func(). But I don't really understand the general
principle at work here.


More information about the Numpy-discussion mailing list