If I have a matrix


And I multiply it with


All three rows change accordingly.

What do I have to do, when I want to change the columns? Is this:


the shortest solution, or do you have better ideas? Because


does not work.

  • $\begingroup$ I think the transpose is a good solution. This also works: vector # & /@ matrix. $\endgroup$
    – Szabolcs
    Oct 6, 2015 at 9:39
  • $\begingroup$ matrix.DiagonalMatrix[vector] $\endgroup$
    – user1066
    Jun 7, 2017 at 23:40

1 Answer 1


This will multiply the vector by each row of matrix individually:

vector # & /@ matrix

and give the same result as

Transpose[matrix] vector // Transpose

Edit: To get rid of all the useful shorthand to see what is going on underneath, this is identical to what I wrote above:

Map[Function[Times[vector, #]], matrix]
  • $\begingroup$ So "applying a number" onto a number in mathematica is the short version for the function multiplication. vector * # & /@ matrix would be the pure way? $\endgroup$
    – mcocdawc
    Oct 6, 2015 at 9:43
  • $\begingroup$ And thank you very much! $\endgroup$
    – mcocdawc
    Oct 6, 2015 at 9:44
  • $\begingroup$ I like to not use the * for multiplication, it muddles things up. You are applying a function vector # - which multiplies vector by the argument, to the list matrix, whose elements are the rows. $\endgroup$
    – Jason B.
    Oct 6, 2015 at 9:45
  • $\begingroup$ Its just to make things clearer for me. I do not want to make so much use of implicit notation in the beginning. Especially now it is easier for me to understand how to make division #/ vector & /@ matrix. And that the application of a number as a function is defined implicitly as multiplication is just Mathematica, it could also be defined as + or something like that. At least I think so. $\endgroup$
    – mcocdawc
    Oct 6, 2015 at 9:49
  • $\begingroup$ Personally, I would use matrix.DiagonalMatrix[vector] (as noted above). $\endgroup$
    – user1066
    Jun 7, 2017 at 23:42

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