# [Numpy-discussion] 2d*3d matrix dot product

Benjamin Root ben.root at ou.edu
Wed Feb 9 12:40:39 EST 2011

```On Wed, Feb 9, 2011 at 9:53 AM, Davide Lasagna <davide.lasagna at polito.it>wrote:

> Hi,
>
> I want to compute the following dot product:
>
> P = np.array( [[ p11, p12 ], [p21, p22]] )
> C = np.array( [c1, c2] )
>
> where c1 and c2 are m*m matrices, so that
>
> C.shape = (2,m,m)
>
> I want to compute:
>
> A = np.array([a1, a2])
>
> where a1 and a2 are two matrices m*m, from  the dot product of P and C.
>
> I would expect:
>
> a1 = p11*c1 + p12*c2
> a2 = p21*c1 + p22*c2
>
> The code should be general so that i can multiply any P and C with shapes:
>
> P.shape = (n, n)
> C.shape = (n, m, l)
>
> and with a result as:
>
> A.shape = (n, m, l)
>
> I had a look at np.dot? but i can't sort out how to transpose/reshape the C
> array.
>
> Any help is greatly appreciated.
>
> Ciao
>
>
tensordot() should do the trick.

A = np.tensordot(P, C, axes=1)

Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110209/a4ab639b/attachment.html>
```