# Elementwise dot multiplication for lists of matrices

I have lists of matrices and want to do element-wise matrix multiplication. Is there an easy way to do this that I've missed?

e.g: {A, B, C}.{X, Y, Z} = {A.X, B.Y, C.Z}

where A, B, C, X, Y, and Z are all matrices.

• C is not a matrix. C is a reserved symbol for constants, you would be well advised to avoid using C, D, E, I, K, N and O except as their built in functions. Commented Jul 11, 2016 at 17:49

MapThread[Dot, {{A, B, C}, {X, Y, Z}}]

{a, b, c, x, y, z} = RandomReal[{0, 1}, {6, 2, 2}]

bk = Dot @@@ Transpose@{{a, b, c}, {x, y, z}}
jd = MapThread[Dot, {{a, b, c}, {x, y, z}}]
bk == jd (*True*)


One can also use Inner[Dot, {a, b, c}, {x, y, z}, List] but you need to wrap lists in Unevaluated:

Inner[Dot, Unevaluated@{a, b, c}, Unevaluated@{x, y, z}, List]


See here for explanation.

• Thanks for pointing out my mistake, it was sloppy of me to not check first. FYI, you could shorten your first line by using RandomReal[{0, 1}, {6,2, 2}]. Commented Jul 12, 2016 at 0:55
• There should be no need for Dot[##] & as Dot can be used directly. Commented Jul 12, 2016 at 2:12