[英]element wise vector or matrix multiplication in Armadillo C++
#include<iostream>
#include<armadillo>
using namespace std;
using namespace arma;
int main()
{
vec x = (1.0/5) * ones<vec>(N); //x is N sized uniformly distributed vector
vec xold(5);
mat v = randu<mat>(3,3);
mat b =randu<mat>(3,3);
mat c = v .* b; //element-wise matrix multiplication
xold = x .* x; // element-wise vector multiplication
}
//----------------------------this is the error message --------------------------------
/*
In function ‘int main()’:
SimilarityMatrix.cpp:182:17: error: ‘b’ cannot be used as a member pointer, since it is of type ‘arma::mat {aka arma::Mat<double>}’
mat c = (v.*b);
^
SimilarityMatrix.cpp:183:14: error: 'x' cannot be used as a member pointer, since it is of type 'arma::vec {aka arma::Col}' xold = x.* x; SimilarityMatrix.cpp:183:14: 错误: 'x' 不能用作成员指针,因为它的类型是 'arma::vec {aka arma::Col}' xold = x.* x; ^ */ //I would appreciate any immediate response. ^ */ //我将不胜感激。
It's explained in the Armadillo documentation . 在Armadillo文档中对此进行了说明 。 You should read all relevant documentation before posting questions on Stackoverflow. 在Stackoverflow上发布问题之前,您应该阅读所有相关文档。
See the section on operators , which states that %
is used for element-wise multiplication: 请参阅关于运算符的部分,其中指出%
用于元素逐个乘法:
mat c = v % b;
It's explained in the Armadillo documentation .犰狳文档中对此进行了解释。
See the section on operators , which states that %
is used for element-wise multiplication:请参阅有关操作符的部分,其中指出%
用于逐元素乘法:
mat = v % b;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.