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.
{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.
RandomReal[{0, 1}, {6,2, 2}].
– Jason B.
Jul 12 '16 at 00:55
Cis not a matrix.Cis a reserved symbol for constants, you would be well advised to avoid usingC,D,E,I,K,NandOexcept as their built in functions. – Feyre Jul 11 '16 at 17:49