# Special Product of two Lists

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


The desired result is

{{{ae, bf}, {ag, bh}}, {{ci, dj}, {ck, dq}}}

• One tangential comment, for a list with constant values, use Set (=) not SetDelayed (:=). – JungHwan Min Dec 18 '16 at 0:51
• Also, do you mean {{{a e, b f}, {a g, b h}}, {{c i, d j}, {c k, d q}}} (b h instead of c h) – JungHwan Min Dec 18 '16 at 0:53
• Yes , i meant that – Ali Dec 18 '16 at 1:01

One way would be

l1 = {{a,b},{c,d}};
l2 = {{{e,f},{g,h}},{{i,j},{k,q}}};

Partition[Riffle[l1,l1],2] l2
(* {{{a e, b f},{a g, b h}},{{c i, d j},{c k, d q}}} *)


The idea behind this solution is to expand l1 into the same shape as l2

Partition[Riffle[l1,l1],2]
(* {{{a,b},{a,b}},{{c,d},{c,d}}} *)


and then use Mathematicas builtin elementwise multiplication on similar shaped lists to get the result.

Another possible solution:

MapTimes[x_,{y_,z_}] := {x y,x z}
MapTimes @@@ Transpose[{l1,l2}]
(* {{{a e, b f},{a g, b h}},{{c i, d j},{c k, d q}}} *)

• It works, thanks for your recommendations – Ali Dec 18 '16 at 1:58
• Glad it works for you! – Thies Heidecke Dec 18 '16 at 2:00
L1 = {{a, b}, {c, d}}
L2 = {{{e, f}, {g, h}}, {{i, j}, {k, q}}}

Transpose[L1 Transpose[L2, {1, 3, 2}], {1, 3, 2}]


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

• Thanks, it is the most appropriate answer for general case – Ali Dec 18 '16 at 3:00
L1 = {{a, b}, {c, d}};
L2 = {{{e, f}, {g, h}}, {{i, j}, {k, q}}};

Transpose /@ (L1*(Transpose /@ L2))

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


or

Thread /@ (L1*(Thread /@ L2))

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

% == %%

(*  True  *)

Flatten[ Flatten[L2, {{1}, {3}}] L1, {{1}, {3}}]


or

Function[x, # x] /@ #2 & @@@ Thread[{L1, L2}]


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