Element-wise multiplication of an array and a matrix
I think the answers given in the comments to the question deserves being on record as a formal answer.
- Bob Hanlon
{x, y, z}*# & /@ {{10, 20, 30}, {0, 1, 2}}
- Henrik Schumacher
{{10, 20, 30}, {0, 1, 2}}.DiagonalMatrix[{x, y, z}]
- user1066
Inner[Times, {{10, 20, 30}, {0, 1, 2}}, {x,y,z}, List]
EDIT: Comparing the timings:
Clear["Global`*"]
n = 20; r = 100;
var = Array[x, n];
mat = Array[m, {r, n}];
t[1] = AbsoluteTiming[prod[1] = var*# & /@ mat;][[1]]
(* 0.001768 *)
t[2] = AbsoluteTiming[prod[2] = mat.DiagonalMatrix[var];][[1]]
(* 0.027773 *)
t[3] = AbsoluteTiming[prod[3] = Inner[Times, mat, var, List];][[1]]
(* 0.001384 *)
Comparing the timings
(t /@ Range[3])/t[3]
(* {1.27746, 20.0672, 1.} *)
Verifying that the different approaches provide identical results.
Equal @@ (prod /@ Range[3])
(* True *)