performance - Reshape three column data to matrix in C++ -


i have file containing 3 columns want reshape matrix.

this question answered in link using r: reshape 3 column data frame matrix ("long" "wide" format)

since input file big want use c++ purpose.

how can create matrix in c++ have fast access element?

after can read big file 3 columns line line , put value in right place using hash key or indexing.

i think map form std lib can 1 dimensional array.

usually when want matrix algebra (since give link r suppose want mathematics data) best use mathematics library. example if use eigen library easy read matrix. after reading matrix there plenty of functions can apply these data. (check benchmarks of library here http://eigen.tuxfamily.org/index.php?title=benchmark) speaking if want linear algebra or vector manipulation best use libraries used/tested/optimized rather use own std::vector<> or std::map<> , write own loops / functions in order manipulate data. linear algebra code not optimized.

#include <iostream> #include <eigen/dense>  int main() {    eigen::matrixxd m(2,3) ;    m << 1, 2, 3,         3, 3, 2;    std::cout << m << std::endl ;    std::cout << "transpose of matrix:" << std::endl;    std::cout << m.transpose() << std::endl;     return 0 ; } 

you can compile , run (in system library has been installed /usr/local/include/eigen3/):

$ g++ matrix.cpp  -i /usr/local/include/eigen3/ -o matrix $ ./matrix  1 2 3 3 3 2 transpose of matrix: 1 3 2 3 3 2 

for example if want transpose matrix can m.transpose() method.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -