Take the 2-minute tour ×

When using arrays I generally use only a one or two dimensional array -- very rarely three or more. I'm just kind of curious, what are some interesting/practical uses for arrays with three or more dimensions? Have you ever used an array with four or more dimensions? I had a professor in college use a six dimensional array in a program he demonstrated in class...ever had more than this?

share|improve this question
In practice it's usually better to only use multi-dimensional arrays as an abstraction and actually store everything in a single 1-d array. This gives safety and performance improvements in most languages (especially those with pointers). –  OrangeDog Feb 9 '11 at 17:39

2 Answers 2

up vote 4 down vote accepted

In scientific programming it can be quite common. We just start calling these higher dimensional arrays tensors. Scalars are 0-dimensional tensors, vectors are 1-dimensional tensors, matrices are 2-dimensional tensors, and after that we just call them d-dimensional tensors (d=3,4,5,6). Dot products are then called contractions over indices.

Where are they used? I use them in some of my physics simulations. For instance, one method for simulating electrons on a lattice (regular array of sites) uses a tensor with a different set of indices for each connection to a neighboring site. In a 2D square lattice (think sites in the center of each space on a chess board), that means that each tensor has four indices, one for each neighboring site, so it is a 4-dimensional tensor.

share|improve this answer

3 dimentions in your array is not that uncommon when dealing with 3D problems, like 3D tetris or such games.

share|improve this answer

Your Answer


