From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Ryan McConnehey
Sent: 12 September 2010 07:37
To: Boost-users
Subject: [Boost-users] [multi-array] Extracting dimension information from a multi-array

 

I'm trying to extract dimension information from a boost multi-array. The documentation gives the following short example.

typedef boost::multi_array<double, 3> array_type;
typedef array_type::index index;
array_type A(boost::extents[3][4][2]);
 
// Assign values to the elements
int values = 0;
for(index i = 0; i != 3; ++i) 
  for(index j = 0; j != 4; ++j)
    for(index k = 0; k != 2; ++k)
      A[i][j][k] = values++;


This is okay if you know the dimension information. Most of the time, though, you don't want to hard code the dimensions into your loop.  The multi_array::dimensionality specifies the dimensions of the array.  How do I find the max elements of each dimension?

Ryan


 

I believe the shape() member function is what you're looking for,