StarBucK
StarBucK

Reputation: 219

How to multiply list of matrices element-wise?

Consider the following code :

A=np.asmatrix([[1, 2],[3,4]])
B=[np.asmatrix([[2,0],[0,2]]), np.asmatrix([[10,0],[0,10]])]

I would like to do a matrix mutliplication which would return me :

C=[A@B[0], A@B[1]]

Is there a built-in method allowing to do this?

Upvotes: 1

Views: 25

Answers (1)

Netwave
Netwave

Reputation: 42708

Use a comprehension:

c = [A@E for E in B]

Upvotes: 3

Related Questions