Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How does one multiply a list of matrices by a list of vectors, elementwise? For example, multiplying

A = {IdentityMatrix[2], 2*IdentityMatrix[2]}
x = {{1, 1}, {2, -2}}

should return

{{1, 1}, {4, -4}}

Neither Dot nor Times accomplishes this; both have the wrong dimensions. A cumbersome way would be

result = {{0, 0}, {0, 0}}
Do[result[[i]] = A[[i]].x[[i]], {i, 2}]

but surely there is a cleaner way.

share|improve this question
up vote 7 down vote accepted
  MapThread[Dot, {A, x}]  (* ? *)
share|improve this answer

Perhaps just:

Dot @@@ Transpose[{A, x}]
share|improve this answer

Following Belasarius in a somewhat more transparent fashion, you Apply[ ] the Dot function to A and x. The Transpose is used to get the A and x into a single list and the "1" causes the Apply to to work at the correct level.

 Apply[Dot, Transpose[{A, x}], 1]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.