[Numpy-discussion] Help with the tensordot function?

Rick Muller rpmuller@gmail....
Fri Sep 3 06:02:47 CDT 2010


Can someone help me replace a slow expression with a faster one based on
tensordot? I've read the documentation and I'm still confused.

I have two matrices b and d. b is n x m and d is m x m. I want to replace
the expression

>>> bdb = zeros(n,'d')
>>> for i in xrange(n):
>>>     bdb[i,:] = dot(b[i,:],dot(d,b[i,:])

with something that doesn't have the for loop and thus is a bit faster.

The first step is

>>> bd = dot(b,d)

However, following this with

>>> bdb = dot(bd,b.T)

doesn't work, since it yields a n x n matrix instead of an n x 1 vector.
Reading the notes on tensordot makes me think it's the function to use, but
I'm having trouble grokking the axes argument. Can anyone help?

Thanks in advance!

-- 
Rick Muller
rpmuller@gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100903/2181a0c4/attachment-0001.html 


More information about the NumPy-Discussion mailing list