I am wondering if there is an efficient and concise way to do an element-wise multiplication of every row (or column) of an Armadillo C++ matrix by a vector. The row (or column) and vector are the same size.
For example, IF fmat::each_row() (and/or each_col()) could be used as an rvalue, I'd want something like this to compile (currently it won't compile):
#include <armadillo>
int main()
{
using namespace arma;
fmat m(20, 10);
fvec v(10); // a column vector
m.each_row() % v.t(); // Currently a compiler error.
return 0;
}
From Armadillo version 5.6 onwards the .each_col()
and .each_row()
methods were expanded to handle out-of-place operations. Hence your suggested approach
m.each_row() % v.t();
should compile, see http://arma.sourceforge.net/docs.html#each_colrow.
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