I am trying to print matrix on the screen.My code:
#include <vector>
#include <algorithm>
#include <cmath>
#include <eigen2/Eigen/Core>
int main() {
std::vector<int> items = {1,2,3,4,5,6,7,8,9,10,11,12,18};
// generate similarity matrix
unsigned int size = items.size();
Eigen::MatrixXd m = Eigen::MatrixXd::Zero(size,size);
for (unsigned int i=0; i < size; i++) {
for (unsigned int j=0; j < size; j++) {
// generate similarity
int d = items[i] - items[j];
int similarity = exp(-d*d / 100);
m(i,j) = similarity;
m(j,i) = similarity;
}
}
for (unsigned int i=0; i < size; i++) {
for (unsigned int j=0; j < size; j++) {
std::cout << m[i][j];
}
std::cout << std::endl;
}
return 0;
}
When I compile I got this:
pex.cpp: In function ‘int main()’:
pex.cpp:25:31: error: invalid types ‘Eigen::ei_traits<Eigen::Matrix<double, 10000, 10000> >::Scalar {aka double}[unsigned int]’ for array subscript
std::cout << m[i][j];
Why do I have invalid types here?Or is there any other way to print the content on the screen?My code will be much larger in the future so I want to check calculations on every step.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire