Multiply the first column of a matrix by several different scalars

I have a matrix, A, which is of size nx2 and a vector, v, of 1000 coefficients.
I would like to create a vector of arrays, A_mult which has 1000 elements, such that every entry in A_mult consists of A with the first column multiplied by a corresponding entry of v.



so essentially I want the first column of A to be multiplied by all the entries in v, and then store the resulting matrices in a new array. Is it possible to do this without a loop?


Out of curiosity, why do you need to avoid a loop? Seems like it would be a bit cumbersome.

1 Like

I suppose I don’t, I was just under the impression that this might not be as efficient as compared to a vectorized form

No, that’s incorrect. Loops are normally the fastest way.


Good to know! Loops it is then!

Matlab, R and Python, etc. have slow loops, while Julia has fast loops, like C or Fortran.


I think you can just write [A .* [s,1]' for s in v].

You should use a loop as other people have said, in Julia the loops are very quickly. Also, you could be interested also in