C#/C++: How to visualize muli-dimensional arrays

How you visualize the arrays really depends on their practical use. If you are using the arrays for spacial relations then you can benefit from imagining it as a cube, but you also lose the need to imagine more than 3 dimensions. If you really and truly wanted to implement a fourth time dimension, you could just imagine your cube with the contents changing as time progresses.

Otherwise you may be keeping track of strongly related records. Perhaps each of the first elements is a galaxy, the second-level elements are star clusters, the third-level elements are solar systems, the fourth-level elements are planets, the fifth-level elements are continents...

In this case you can imagine it was arrays within arrays. If you need a 4-dimensional array then you can imagine a cube, but each sub-cube is actually a one-dimensional array.

If you need a 5-dimensional array then you can imagine a cube, but each sub-cube is divided into your "brick wall" example.

6-dimensional is a cube with each sub-cube being its own divided cube.

This tends to fall apart at after 6 dimensions. Beyond this there is usually a more practical reason that you need so many dimensions. For example, websites like eHarmony do their match-making by using normal geometry on 20+ -dimensional spaces. You have one dimension for "humor", one for "good looks", one for "love of shopping"... Then you can take two people and apply distance formula (square each of the dimensional differences, add these differences, square root) and determine how compatible the two people are. So if one person scored "5, 3, 9, 2, 8, 4, 7, 3, 1" on our 9-dimensional personality matrix and another scored "9, 3, 7, 1, 8, 2, 8, 4, 7" then your compatibility is:

sqrt((5-9)^2+(3-3)^2+(9-7)^2+...)

This can be applied over infinite dimensions and still work. Since these dimensions don't apply to space, however, there's no need to visualize them as such. Instead, in this particular case, we can actually imagine it as just a single-dimensional array with several integer values. The reason we can simplify this array, mind you, is that our multi-dimensional array only contains a single "1" and all of the rest are "0"s (indicating the location of the person in this array).

Moving away from the eHarmony example, the point is- after a certain amount of dimensions you usually have a practical purpose for the array which lends itself to a method of perceiving it.


Some people can mentally model n-dimensional geometry for n > 3, at least as far as simple shapes go, and some cannot. (I was quite surprised when recently talking to someone whose field was advanced n-dimensional geometry to learn that he couldn't visualise a hypercube, while I can but find his mathematics quite beyond me).

It isn't really necessary though. Indeed, it's rarely particularly necessary to visualise a two-dimensional array as Cartesian coördinates either - when you are using a 2-dimensional array in practice you have some purpose for each axis, and that purpose quickly becomes more important than any visual representation.

If you do need to, then consider that a 2-dimensional array can also be considered as an ordered set of 1-dimensional structures. Likewise a 3-dimensional array can be considered an ordered set of 2-dimensional structures, or a set of sets of 1-dimensional (with these sets of equal size - allowing different sizes moves matters into jagged arrays).

Hence a 4-dimensional array can be considered an ordered set of 3-dimensional structures, and so on.


You don't. It's rare that you even need more than 2 or 3 dimensions. If you need more than that, then perhaps the extra dimensions should be modeled as properties on an object instead, in which case you can see them as attributes and not try to imagine some mythical hypercube.