Is there an in-built function in octave to multiply each column of a m X n
element-wise with a column vector of size m
that is more efficient than using a loop?
Matrix-vector product If we let Ax=b, then b is an m×1 column vector. In other words, the number of rows in A (which can be anything) determines the number of rows in the product b. The general formula for a matrix-vector product is Ax=[a11a12… a1na21a22…
We can only multiply an m × n matrix by a vector in Rn. That is, in Ax the matrix must have as many columns as the vector has entries. If we multiply an m × n matrix by a vector in Rn, the result is a vector in Rm. Ax = b.
In mathematics, the Hadamard product (also known as the element-wise product, entrywise product or Schur product) is a binary operation that takes two matrices of the same dimensions and produces another matrix of the same dimension as the operands, where each element i, j is the product of elements i, j of the ...
You can replicate the vector as many times as you need to turn it into a m x n
matrix as well and then use the built-in element-wise multiplication operator .*
:
>> A = [1 2; 3 4; 5 6]; >> B = [1; 2; 3]; >> A .* repmat(B, 1, columns(A)) ans = 1 2 6 8 15 18
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With