High Dimension Arrays
In previous sections, we saw how easy it is to create and manipulate one-dimensional arrays (vectors), two-dimensional arrays (matrices), three-dimensional arrays, and four-dimensional arrays. In this section, we describe some of the features for working with arrays of five, six, and even higher dimensions. These techniques can also be used to write code that can deal with arrays of arbitrary dimension. Combined with automatic type conversion from vectors and matrices to arrays, this allows you to write subroutines which can be used with vectors, matrices, and arrays.
First, here is a quick reminder of the most basic method for constructing a three-dimensional array:
 
RWMathArray<double> A(5,5,5, rwUninitialized); //A 5x5x5 array
Similarly, you can construct a four-dimensional array like this:
 
RWMathArray<double> A(5,5,5,5, rwUninitialized); //A 5x5x5x5 array
Beyond four dimensions, things become a little trickier. Rather than providing an infinite number of constructors like the ones for three-dimensional and four-dimensional arrays, we provide a constructor that takes an RWIntVec, a vector of integers, as a parameter. This is used to provide the sizes of the array in each dimension:
 
RWIntVec L("[5 5 5 5 5]");
RWMathArray<double> A(L, rwUninitialized); // A 5x5x5x5x5 array
It is often useful to construct arrays of less than three dimensions as well. These are created using type conversion from vectors and matrices. For example:
 
RWMathVec<double> v("[3 5 2 1 9]");
RWMathArray<double> A = v; // A 1-D, length 5 array
Here A and v now provide alternative views of the same data. This constructor is often used to pass vectors and matrices to subroutines written to work on an arbitrary dimension array.
Subscripting individual elements from arrays is done by using an integer vector as the subscript:
 
RWIntVec i("[3 1 2 3 1]");
double x = A(i); // Access A(3,1,2,3,1)
Subscripting groups of elements from high dimension arrays is done using the slice() member function described in the SourcePro API Reference Guide.