Generic way to apply function to a dimension of a matrix

This particular computation is exactly a matrix product, so just doing M * v' will be the best approach.

More generally, you can use the eachslice, eachrow, or eachcol iterators.

Is there a generic way to do this without for loops?

Note also that there’s nothing wrong with a loop in Julia. Loops are fast, and are sometimes the simplest and clearest way to code something.

6 Likes