How do I store a 100000*100000 matrix in C++? -
i have 2 vectors a[100000]
, b[100000]
. want store a[i]*b[j]
in matrix. how can in c++?
you can use std::vector<std::vector<your_type>>
store result.
int rows = 100000, cols = 100000; std::vector<std::vector<double>> result; result.resize(rows); for(int i=0; i<rows; i++) { result[i].resize(cols); } for(int i=0; i<rows; i++) { for(int j=0; j<cols; j++){ result[i][j] = a[i] * b[j]; } }
or can use linear algebra library, example eigen (you'll may have less code this), will surely more efficient.
Comments
Post a Comment