Reputation: 406
Is it possible to multiply (dot product) a matrix by a vector in Armadillo ? It seems to me a basic operation we expect from this kind of library, so it should exist. All my attempts failed up to now:
"matrix multiplication: incompatible matrix dimensions: 1206x36 and 1x1206"
"matrix multiplication: incompatible matrix dimensions: 1206x36 and 1206x1"
"matrix multiplication: incompatible matrix dimensions: 1x1206 and 1206x36"
"matrix multiplication: incompatible matrix dimensions: 1206x1 and 1206x36"
Upvotes: 0
Views: 5294
Reputation: 1381
Yes, it is possible. Can you provide a sample of the source code used to produce the errors above? Try the following, as it should work fine.
arma::mat X ;
arma::vec beta ;
beta.resize ( 2 ) ;
beta (0) = 1.0 ;
beta (1) = 3.0 ;
X.resize ( 3, 2 ) ;
X (0,0) = 1.0 ;
X (0,1) = 2.0 ;
X (1,0) = 3.0 ;
X (1,1) = 4.0 ;
X (2,0) = 5.0 ;
X (2,1) = 6.0 ;
std::cout << X * beta << std::endl ;
It will also work if both are defined as type "arma::mat", too, as long as the dimensions are compatible.
Upvotes: 3