title: double multidimensional array,in c++, the best way
body: <p>This thread in SO is about <strong>multidimensional array in c+</strong>+.</p>
  
  <p>I have to port some code from c# to cpp. i have code like this:</p>
  
  <pre><code>private double[,] B;
  ...
  this.B = new double[states, symbols];
  double[][, ,] epsilon = new double[N][, ,]; 
  double[][,] gamma = new double[N][,];
  ...
  s += gamma[i][t, k] = ...
  </code></pre>
  
  <p>i have thought to use plain <strong>double array of array</strong> but it's quite pain. another solution could be <strong>vector of vector</strong> of double, or a <strong>custom Matrix2D and Matrix3D classes</strong>?</p>
  
  <p>what is the best way for each of those cases?</p>
  
  <hr>
  
  <hr>
  
  <p><strong>WHAT I LEARNED:</strong></p>
  
  <ul>
  <li><p>multidimensional array in c++ is a great topic, and internet is full of resources. it could be  handled in various ways, some of them really tricky, some others more faster to write.</p></li>
  <li><p>i think that the best way is to deal with it is to use some libraries that takes in account this topic. there are a lot of them: <a href="http://arma.sourceforge.net/docs.html#syntax" rel="nofollow noreferrer">Armadillo</a> (nice MATLAB syntax conversion),  <a href="http://eigen.tuxfamily.org/dox/TutorialMatrixClass.html" rel="nofollow noreferrer">Eigen</a> i think is one of the better one, easy to install, easy to use, powerfull. <a href="http://www.boost.org/doc/libs/1_48_0/libs/multi_array/doc/index.html" rel="nofollow noreferrer">Boost::multi_array</a> is anotherone, and Boost is really a famous lib that is important just to take a look at how it handle the topic. As <a href="https://stackoverflow.com/a/9011538/433685">Konrad Rudolph answer</a> <a href="http://www.cplusplus.com/forum/articles/7459/" rel="nofollow noreferrer">STD with nested vectors</a> or <a href="https://stackoverflow.com/a/3904484/433685">this</a> could be another solution but, after a little search, i think the less elegant even the more easy and fast to code without external libs.</p></li>
  <li><p>write a custom class. mayebe such a good exercice. <a href="https://stackoverflow.com/a/9011601/433685">peter answer</a> or <a href="https://stackoverflow.com/a/341193/433685">this</a> or <a href="https://stackoverflow.com/a/6587618/433685">this</a> are a good start point and also <a href="https://stackoverflow.com/questions/340943/c-multi-dimensional-arrays-on-the-heap/341193#341193">this post</a> is interesting but expecially this <a href="http://www.eld.leidenuniv.nl/~moene/Home/tips/matrix2d/" rel="nofollow noreferrer">great post blog from <strong>martin moene</strong></a> (one of the best essay on this topic i've read today). I mention also this answer for <a href="https://stackoverflow.com/a/4311/433685">sparse array</a>.</p></li>
  <li><p>here is a <a href="http://www.stroustrup.com/Programming/Matrix/Matrix.h" rel="nofollow noreferrer">nice tutorial</a> direct from stroustrup </p></li>
  <li><p>have a nice time with multidimensional array :-)</p></li>
  </ul>