[Numpy-discussion] Simplified question on tensordot
Pauli Virtanen
pav@iki...
Fri Sep 3 06:57:22 CDT 2010
Fri, 03 Sep 2010 05:48:31 -0600, Rick Muller wrote:
[clip]
> I want to take the product AB such that I get a length-n vector, as in:
>
> >>> AB = zeros(n,'d')
> >>> for i in xrange(n):
> >>> AB[i] = dot(A[i,:],B[i,:])
>>> AB = np.sum(A*B, axis=1)
It does create an intermediate (n, d) matrix, however. If this is a
problem because of memory issues, you can try numexpr [1],
>>> numexpr.evaluate("sum(A*B, axis=1)")
.. [1] http://code.google.com/p/numexpr/
--
Pauli Virtanen
More information about the NumPy-Discussion
mailing list