Hello,
I have a matrix of int (vector of vector); the problem is that I need to compute the mean of each column (the matrix can be 500 x200); so to do this I did:
Qt Code:
  1. foreach (iter_column) {
  2. float sum = 0;
  3. iter_line.setFirstLine;
  4. foreach(iter_line) {
  5. sum += iter_line[iter_coulmn]. value;
  6. }
  7. mean = sum / nOfLine;
  8. }
To copy to clipboard, switch view to plain text mode 
The problem is that I have to do "two for" one inside other; I thought If is better to do something like to tie a vector<coulum> and do:
Qt Code:
  1. class Column {
  2. public:
  3. vector<double> _value;
  4. };
  5. vector<Column> col; //to fill col properly
  6. foreach (col) {
  7. int sum = std::accumulate(col.begin(), col.end(), 0);
  8. mean = sum / col.size();
  9. }
To copy to clipboard, switch view to plain text mode 

Will be the second way better/faster? Any other ways to improve?