title: How to store values in the boost multi_array container?
body: <p>I'm struggling to access the values and store them in boost multi_array container. I've tried to access the elements using the indexing methods ([] and .at()), but throws <strong>error: no matching function for call to 'boost::multi_array&lt;float, 2&gt;::data(int)'</strong>, however I can print the data (see the code) but do not have any idea how to store it and access it again for further computations. The data is two dimensional(11214, 3), but for the meantime I just want to flatten it and have a sequence of values. So my question is how to access the elements and how to store them in the container?</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;boost/multi_array.hpp&gt;
  #include &lt;boost/timer/timer.hpp&gt;
  #include &lt;boost/range/irange.hpp&gt;
  #include &lt;h5xx/h5xx.hpp&gt;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  #include &lt;iterator&gt;
  #include &lt;string&gt;
  
  using array_2d_t = boost::multi_array&lt;float, 2&gt;;
  //using array_2d_t = boost::multi_array&lt;float, 3&gt;;
  template &lt;typename T&gt; 
  void print_array(T const&amp; array)
  {
      for (auto const&amp; row : array) 
          { for (auto v : row)
              printf(&quot;%10f &quot;, v);
          printf(&quot;\n&quot;); //prints a new line similar t0 \n
      }
  }
  
  h5xx::dataset open_dataset(std::string const&amp; filename) {
      h5xx::file xaa(filename, h5xx::file::mode::in);
      h5xx::group g(xaa, &quot;particles/lipids/box/positions&quot;);
      return h5xx::dataset(g, &quot;value&quot;);
  }
  
  std::vector&lt;float&gt; cell_from_all_frames(h5xx::dataset&amp; ds, size_t row, size_t col) {
      // determine dataset shape: frames, particle count, space dimension
      auto ds_shape = h5xx::dataspace(ds).extents&lt;3&gt;();
      std::vector&lt;float&gt; cells(ds_shape[0]); // number of frames
  
      std::vector&lt;hsize_t&gt; offsets{0, row, col};
      std::vector&lt;hsize_t&gt; counts{ds_shape[0], 1, 1};
      h5xx::slice slice(offsets, counts);
  
      h5xx::read_dataset(ds, cells, slice);
      return cells;
  }
  
  array_2d_t read_frame(std::string const&amp; filename, unsigned frame_no) {
      //h5xx::file xaa(&quot;../../data/xaa.h5&quot;, h5xx::file::mode::in);
      h5xx::file xaa(filename, h5xx::file::mode::in);
  
      h5xx::group   g(xaa, &quot;particles/lipids/box/positions&quot;);
      h5xx::dataset ds(g, &quot;value&quot;);
  
      // determine dataset shape: frames, particle count, space dimension
      auto ds_shape = h5xx::dataspace(ds).extents&lt;3&gt;();
      array_2d_t arr(boost::extents[ds_shape[1]][ds_shape[2]]);
  
      std::vector&lt;hsize_t&gt; offsets{frame_no, 0, 0};
      std::vector&lt;hsize_t&gt; counts{1, arr.shape()[0], arr.shape()[1]};
      h5xx::slice slice(offsets, counts);
  
      h5xx::read_dataset(ds, arr, slice);
      return arr;
  }
  
  int main(int argc, char const* argv[])
  {
      if (argc &lt; 2) {
          std::cout &lt;&lt; &quot;Usage: &quot; &lt;&lt; argv[0] &lt;&lt; &quot; input.h5&quot; &lt;&lt; std::endl;
          return -1;
      }
  
      auto ds = open_dataset(argv[1]);
      std::vector&lt;float&gt; first_cells = cell_from_all_frames(ds, 0, 0);
  
      // set up multi-tau correlator for the computation of time correlation functions
      size_t nsamples = 10;            // FIXME obtain these parameters from HDF5 file. These 10 elements would be first element of first row, first element of 11214 row, first element of 11214*2 row, first element of 11214*3 row ,..., first element of 11214*10 row.
    return 0;
  }
  </code></pre>
  <p>In the main() I read the data from function read_frame and try to pass it to the nsamples. I've tried few things but it doesn't work!!</p>