4
$\begingroup$

Hello I would like to multiply a list of matrices by another list of matrices and return all elements. I.e.

K={A,B,C}
L={X,Y}

And the result should be

K.L={A.X,B.X,C.X,A.Y,B.Y,C.Y}

I tried

Outer[Dot,A,B]

but it did not work.

$\endgroup$
4
  • 3
    $\begingroup$ Does Dot @@@ Tuples[{{a, b, c}, {x, y}}] give what you need? $\endgroup$
    – kglr
    Commented Jan 19, 2017 at 1:00
  • 1
    $\begingroup$ .. or Join @@ Transpose@Outer[Dot, {a, b, c}, {x, y}]? $\endgroup$
    – kglr
    Commented Jan 19, 2017 at 1:05
  • $\begingroup$ It does! The order is slightly different - it is {a.x, a.y,....} but it doesn't matter. Thanks! $\endgroup$ Commented Jan 19, 2017 at 1:11
  • $\begingroup$ @kglr, make an answer dude and we will upvote it!! $\endgroup$
    – ivbc
    Commented Jan 19, 2017 at 1:29

1 Answer 1

4
$\begingroup$
Dot @@@ Tuples[{{a, b, c}, {x, y}}]
(* or *) Join @@ Transpose@Outer[Dot, {a, b, c}, {x, y}]
(* or *) Distribute[{{a, b, c}, {x, y}}, List, List, List, Dot]

{a.x, a.y, b.x, b.y, c.x, c.y}

If the order matters use SortBy:

Dot @@@ Tuples[{{a, b, c}, {x, y}}] // SortBy[#, Last]&

{a.x, b.x, c.x, a.y, b.y, c.y}

Or, if you have version 10 or 11, just SortBy[Last] instead of SortBy[#, Last]&.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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