[Numpy-discussion] confused about tensordot

Bradley M. Froehle brad.froehle@gmail....
Fri Feb 15 12:04:46 CST 2013


>
> >> It's supposed to take 2 matrixes, each (1004, 13) and do element-wise
> >> multiply,
> >> then sum over axis 0.
> >>
>
> Can I use tensordot to do what I want?


No.  In your case I'd just do (a*b.conj()).sum(0).  (Assuming that a and b
are arrays, not matrices).

It is most helpful to think of tensordot as a generalization on
matrix multiplication where the axes argument gives the axes of the first
and second arrays which should be summed over.

a = np.random.rand(4,5,6,7)
b = np.random.rand(8,7,5,2)
c = np.tensordot(a, b, axes=((1, 3), (2, 1))) # contract over dimensions
with size 5 and 7
assert c.shape == (4, 6, 8, 2) # the resulting shape is the shape given by
a.shape + b.shape, which contracted dimensions removed.

-Brad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130215/090455de/attachment.html 


More information about the NumPy-Discussion mailing list