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

Davide Lasagna davide.lasagna at polito.it
Wed Feb 9 10:53:06 EST 2011


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 

Any help is greatly appreciated.


More information about the NumPy-Discussion mailing list