# Multiply each element of an array by another array?

I would like to multiply an array by each element of another array, and am having a lot of trouble finding a built-in or automated method of doing.

Here is an example of what I'd like to achieve:

a = 0.5;
b = 4.0;

mat = {{0, 1}, {a, b}};
Rmat = RandomInteger[10, {4, 4}]
m11 = mat[[1, 1]]*Rmat;
m12 = mat[[1, 2]]*Rmat;
m21 = mat[[2, 1]]*Rmat;
m22 = mat[[2, 2]]*Rmat;

fmat = ArrayFlatten[{{m11, m12}, {m21, m22}}]


As you can see, the first matrix mat is multiplied by each individual element of Rmat. I feel like this should be easy, but I'm not finding a built-in function that works?

Thanks!

## 3 Answers

ArrayFlatten[Outer[Times, mat, Rmat]]

• Those both work thanks! Mar 7 '14 at 4:16
• @rasher...good old Outer,+1 Mar 7 '14 at 4:45

Try this:

ArrayFlatten[Map[Rmat*# &, mat, {2}]]


It was apparently missed by the other posters that KroneckerProduct[] is built-in:

KroneckerProduct[mat, Rmat]

• Yep. Forgot it....
– ciao
Aug 21 '15 at 19:57
• J.M Could you help me question if you have time now? Please see here and here
– xyz
Aug 22 '15 at 7:40
• @Shutao, not sure what those pictures are supposed to be. Why not write a proper question instead of a comment? Aug 22 '15 at 8:11
• @Guesswhoitis. I think this small question could be solved in the chatting room.
– xyz
Aug 22 '15 at 8:14
• Maybe this picture can express what I need.
– xyz
Aug 22 '15 at 8:22