title: C++ Armadillo: mat initialization from vector<vector<double>> destroys data
body: <p>I'm trying to initialize data from a vector of vectors to armadillo mat. </p>
  
  <p>found this site explaining how to do it: </p>
  
  <p><a href="http://www.kaiyin.co.vu/2014/07/initialize-armadillo-matrix-with-std.html" rel="nofollow">http://www.kaiyin.co.vu/2014/07/initialize-armadillo-matrix-with-std.html</a></p>
  
  <p>after printing the vector of vectors  and the resulting mat i came to the conclusion  that armadillo makes garbage of my data. </p>
  
  <p>the main part of my function: </p>
  
  <pre><code> vector&lt;vector&lt;double&gt;&gt; C_mat(num_of_functions,vector&lt;double&gt;(num_of_points));
          for(int j=0; j&lt; num_of_functions; ++j)
          {
              for( int i=0;i&lt;num_of_points; ++i)
              {
                  C_mat[j][i]=(functions[j](points[i].x()));// shouldn't bother you, this works. 
              }
          }
          mat C(&amp;(C_mat.front()).front(),num_of_points, num_of_functions);
  
          cout &lt;&lt; C &lt;&lt; endl &lt;&lt; endl;
          for(int i=0; i&lt; num_of_functions;++i)
          {
              print_vec(C_mat[i]);
          }
  </code></pre>
  
  <p>print_ve(vector) is a function i wrote that prints a vector.</p>
  
  <p>output:</p>
  
  <pre><code>    1.0000e+00        0e+00   1.9965e+01
      1.0000e+00  4.7924e-322   1.2822e+00
      1.0000e+00   1.1683e+01        0e+00
      1.0000e+00   1.6936e+01  4.7924e-322
      1.0000e+00   2.3361e-01   1.0237e+02
      1.0000e+00   1.6445e+01   2.1512e+02
      1.0000e+00   7.4271e+00   4.0931e-02
      1.0000e+00   1.4162e+01   2.0284e+02
      1.0000e+00   1.1670e+01   4.1371e+01
      1.0000e+00   2.3633e+00   1.5042e+02
  </code></pre>
  
  <p>printing vector: </p>
  
  <p>1
  1
  1
  1
  1
  1
  1
  1
  1
  1</p>
  
  <p>printing vector: </p>
  
  <p>11.6828
  16.9359
  0.233613
  16.4455
  7.42708
  14.1619
  11.6701
  2.36329
  19.9653
  1.28223</p>
  
  <p>printing vector: </p>
  
  <p>102.366
  215.119
  0.0409313
  202.84
  41.3711
  150.421
  102.143
  4.18885
  298.959
  1.23308</p>
  
  <p>UPDATE:</p>
  
  <p>I tried changing the code with respect to the first comment by essentially making my own 2D vector out of 1D vector. now armadillo does not destroy the data but scrambles it: </p>
  
  <pre><code>        vector&lt;double&gt; C_mat(num_of_functions*num_of_points);   
          for( int i=0;i&lt;num_of_points; ++i)
          {
              for(int j=0; j&lt; num_of_functions; ++j)
              {
                      C_mat[i*num_of_functions+j]= functions[j](points[i].x());
              }
          } 
          mat C(&amp;C_mat.front(),num_of_points, num_of_functions);
  </code></pre>
  
  <p>output: </p>
  
  <pre><code>     1.0000e+00   1.1170e+01   1.6853e+01
       4.5538e+00   9.3574e+01   1.0000e+00
       1.5553e+01   1.0000e+00   1.6292e+01
       1.0000e+00   8.7956e-01   1.9907e+02
       6.0653e+00   5.8021e-01   1.0000e+00
       2.7591e+01   1.0000e+00   1.0787e+01
       1.0000e+00   1.8169e+01   8.7269e+01
       1.3849e+01   2.4758e+02   1.0000e+00
       1.4385e+02   1.0000e+00   1.7998e+01
       1.0000e+00   4.7403e+00   2.4295e+02
  
  
     1  4.5538  15.5528 
     1  6.06532  27.5911 
     1  13.8494  143.854 
     1  11.1698  93.574 
     1  0.879557  0.580215 
     1  18.1687  247.577 
     1  4.74031  16.8529 
     1  16.2919  199.069 
     1  10.787  87.2695 
     1  17.998  242.945 
  </code></pre>