# Multilpe matrix (mxm) and vector (n), wich are unequal, so get a (three dimensional matrix) mxmxn matrix

For example I have this matrix:

mk = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}

and I'd like it to multiple with this:

ot = Table[5, {4}]
{5,5,5,5}

to get this one:

{{{ 5, 5, 5, 5}, {10,10,10,10}, {15,15,15}},
{{20,20,20,20}, {25,25 ...}...}...}

but KroneckerProduct gives me 3 rows instead of a 3 x 3 x 4 matrix (similar but not identical). Of course I have really large lists...

KroneckerProduct[mk, ot]
{{5, 5, 5, 5, 10, 10, 10, 10, 15, 15, 15, 15},
{20, 20, 20, 20, 25, 25, 25, 25, 30, 30, 30, 30},
{35, 35, 35, 35, 40, 40, 40, 40, 45, 45, 45, 45}}
-
Use Map at the second level Map[{5, 5, 5, 5} # &, {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, {2}]. – Artes Dec 16 '13 at 12:10
How about Outer[Times, {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, {5, 5, 5, 5}]? – Jacob Akkerboom Dec 16 '13 at 12:11
Thank you! These were very helpful! – szms Dec 16 '13 at 12:17

m = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
v = {5, 5, 5, 5};

KroneckerProduct[m, {{v}}]
{{{5, 5, 5, 5}, {10, 10, 10, 10}, {15, 15, 15, 15}}, {{20, 20, 20, 20}, {25, 25, 25,
25}, {30, 30, 30, 30}}, {{35, 35, 35, 35}, {40, 40, 40, 40}, {45, 45, 45, 45}}}

At least in version 7 Outer as recommended by Jacob is somewhat faster however:

m = RandomReal[9, {50, 100}];
v = RandomReal[9, 127];

KroneckerProduct[m, {{v}}] ~Do~ {500} // Timing // First
Outer[Times, m, v] ~Do~ {500}         // Timing // First
1.373

0.733
-
+1 and the timings are similar in proportion on version 9 – Jacob Akkerboom Dec 16 '13 at 12:43