Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

For example: A two-dimensional array can be visualized like a brick-wall with square bricks, where every brick represents a coordinate in our array. A 3-dimensional array can in the same way be visualized as a box, or cube.

But, here is the tricky part, how do you visualize an array with multiple (More than 3) dimensions? Or, for that part, how do you visualize an array with not only multiple dimensions, but multiple dimensions in several layers?

For example: How do you visualize an array such as this: Array[3,3,3,3][3,3][3,3,3,3,3][3]?

like image 580
Marcus Hansson Avatar asked Nov 19 '10 00:11

Marcus Hansson


5 Answers

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.

like image 110
stevendesu Avatar answered Oct 19 '22 17:10

stevendesu


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.

like image 41
Jon Hanna Avatar answered Oct 19 '22 17:10

Jon Hanna


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.

like image 29
mpen Avatar answered Oct 19 '22 17:10

mpen


There are many lovely ways to visualize multidimensional data. One of my favorites is Alfred Inselberg's Parallel Coordinates, which represents each dimension as a vertical axis, and each data point as a thread connecting them all:

alt text

Another great visualization is Ramana Rao's Table Lens (pdf):

alt text

This represents each dimension as a column, as in a spreadsheet, but graphically rather than numerically. It is particularly good at showing correlation between dimensions; as you sort by one dimension, it is easy to see how correlated dimensions sort alongside it.

like image 45
Carl Manaster Avatar answered Oct 19 '22 18:10

Carl Manaster


Try being subtractive about it. If you need to imagine, say, a ten dimensional array then start by imagining the set of all n-dimensional real-valued Euclidean vector spaces for all finite non-negative integers n. { R0, R1, R2, ... }

Now imagine taking away almost all of that, leaving just R10.

Now imagine taking away almost all of that, so that you have just the integer lattice points in R10 left.

Now imagine taking away almost all of that, so that you have just a hyper-rectangular subset of the integer lattice points.

And you're done; that's a good visualization of a 10-dimensional array. It's really very small when you think about it as a subset of the set of all possible n-dimensional vector spaces.

If the subject of high-dimensional spaces interests you, you might want to read my gentle introduction to some interesting facts about search algorithms on high-dimensional vector space databases:

http://blogs.msdn.com/b/ericlippert/archive/tags/high+dimensional+spaces/

like image 3
Eric Lippert Avatar answered Oct 19 '22 16:10

Eric Lippert