11
$\begingroup$

Please, for the two lists:

L1 := {{a, b}, {c, d}, {e, f}} 
L2 := {{g, h, i}, {j, k, q}}

I need the result

{{{a g, a h, a i}, {c g, c h, c i}, {e g, e h, e i}}, 
 {{b j, b k, b q}, {d j, d k, d q}, {f j, f k, f q}}}
$\endgroup$
  • $\begingroup$ Look up Outer[] and MapThread[]. $\endgroup$ – J. M. will be back soon Dec 17 '16 at 8:17
  • $\begingroup$ I tried, i think there is additional some thing with any of them $\endgroup$ – Ali Dec 17 '16 at 8:19
  • $\begingroup$ Outer provide more terms than this result and MapThread provide less one. $\endgroup$ – Ali Dec 17 '16 at 8:22
14
$\begingroup$

Also

Transpose @@ Outer[Times, {L2}, L1, 1]

Transpose[# L2 & /@ L1]
$\endgroup$
  • $\begingroup$ Last one is pretty, +1 $\endgroup$ – ciao Dec 28 '16 at 0:38
13
$\begingroup$
MapThread[Outer[Times, #, #2] &, {L1\[Transpose], L2}]

Or simpler:

MapThread[KroneckerProduct, {L1\[Transpose], L2}]
$\endgroup$
  • $\begingroup$ Many thanks for you, it works. $\endgroup$ – Ali Dec 17 '16 at 8:51
  • $\begingroup$ @Ali if this worked for you consider accepting the answer. Benefits the answerer and also indicates to people that the question has been answered sufficiently well. $\endgroup$ – b3m2a1 Dec 27 '16 at 23:05
1
$\begingroup$

Also

KroneckerProduct @@@ Transpose@{Transpose@L1, L2}
Outer[Times, ##] & @@@ Transpose@{Transpose@L1, L2}

{{{a g, a h, a i}, {c g, c h, c i}, {e g, e h, e i}}, {{b j, b k, b q}, {d j, d k, d q}, {f j, f k, f q}}}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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