c++ - error: invalid types for array subscripts -
i trying print matrix on 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); (unsigned int i=0; < size; i++) { (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; } } (unsigned int i=0; < size; i++) { (unsigned int j=0; j < size; j++) { std::cout << m[i][j]; } std::cout << std::endl; } return 0; }
when compile 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]’ array subscript std::cout << m[i][j];
why have invalid types here?or there other way print content on screen?my code larger in future want check calculations on every step.
isn't there an operator display matrix without having write loops hand?
std::cout << m << std::endl;
otherwise, want call operator()
not operator[]
:
std::cout << m(i, j);
don't you?
Comments
Post a Comment