Armadillo C ++中的元素智能向量或矩阵乘法

时间:2014-11-06 22:01:19

标签: c++ armadillo

#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:错误:'x'不能用作成员指针,因为它的类型为'arma :: vec {aka arma :: Col}'   xold = x。* x;               ^     * /     //我很感激任何立即的回应。

1 个答案:

答案 0 :(得分:9)

Armadillo documentation中对此进行了解释。在Stackoverflow上发布问题之前,您应该阅读所有相关文档。

请参阅operators部分,其中指出%用于逐元素乘法:

mat c =  v % b;