7

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]?

Marcus Hansson
  • 816
  • 2
  • 8
  • 17
  • 3
    Your array gives 4x2x.... > 100 dimensions. Even String Theory gives only 10 or 12 dimensions! – xandy Nov 19 '10 at 00:28
  • 3
    @xandy: The physical word is an especially poor analogy. *From a bit to a few hundred megabytes, from a microsecond to a half an hour of computing confronts us with completely baffling ratio of 10\*\*9! The programmer is in the unique position that his is the only discipline and profession in which such a gigantic ratio, which totally baffles our imagination, has to be bridged by a single technology. He has to be able to think in terms of conceptual hierarchies that are much deeper than a single mind ever needed to face before.* — E. W. Dijkstra – Fred Nurk Nov 19 '10 at 00:33
  • @Fred, though the pure mathematician might consider that as limited as @xandy's analogy to the physical world :) – Jon Hanna Nov 19 '10 at 00:44
  • 1
    @Jon: I daresay Dijkstra wouldn't disagree: *Programming is one of the most difficult branches of applied mathematics.* — E. W. Dijkstra, EWD498 – Fred Nurk Nov 19 '10 at 00:47
  • @Fred: Absolutely true. It is pretty interesting though that, as a programmer, we have such immense options. Just the fact that we can instantiate an array with several thousand indexes, in more dimensions than we can easily visualize is impressive. – Marcus Hansson Nov 19 '10 at 00:48

13 Answers13

12

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.

stevendesu
  • 15,753
  • 22
  • 105
  • 182
5

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.

Jon Hanna
  • 110,372
  • 10
  • 146
  • 251
4

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.

mpen
  • 272,448
  • 266
  • 850
  • 1,236
  • 2
    Of course I know and understand that you don´t ever need (Or use for that matter) that big arrays. But the very thought of such extreme dimensions is pretty baffling, not to mention how interesting it is to discuss. On a less serious note; You made my day with that answer, thank you for that! – Marcus Hansson Nov 19 '10 at 00:44
  • @Marcus: Well, that's the thing. It *is* baffling. Sometimes it's fun to try and imagine such things, but it just isn't practical. Glad you liked my answer :) – mpen Nov 19 '10 at 07:21
4

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.

Carl Manaster
  • 39,912
  • 17
  • 102
  • 155
3

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/

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Eric Lippert
  • 647,829
  • 179
  • 1,238
  • 2,067
1

You could visualise a financial report as an array where data is coming in from multiple entities in spreadsheet form:

  • a single spreadsheet of sales data would be a 2D array (e.g. sales for each month in the quarter per profit centre);
  • multiple tabs in a workbook (one for each subsidiary) would be a 3D array;

Then, for purposes of global consolidation, a Controller may receive a workbook from each Region - this would be the 4th dimension. A fifth dimension could be "time" if you have a need to manipulate sales data over time (to spot trends for instance).

In theory, you could hold multi-year, multi-region sales data in a single 5D array variable.

As people have said above, you really need to have an application in mind first and then the logical data structure will help define a suitable physical form. Any set of attributes that can be modelled relationally can be placed in an array normally.

tony

Tony C
  • 11
  • 2
1

Over 3 dimensions, your only options are either a tree view or a drill-down.

Stu
  • 15,675
  • 4
  • 43
  • 74
1

The same way you visualize 4 spatial dimensions: "slice", superimpose, or project it onto what you already understand and can visualize.

Fred Nurk
  • 13,952
  • 4
  • 37
  • 63
1

Think of every extra dimension as an "enclosing box". Think of a 2D array as an array of 1D arrays, of a 3D array as an array of 2D arrays, and so on.

Here are some examples...

1D 1x2 array:

[ 1, 2 ]

2D 2x2 array:

{ [ 1, 2 ], [ 3, 4 ] }
{ [ 5, 6 ], [ 7, 8 ] }

3D 2x2x2 array:

( { [ 1, 2 ], [ 3, 4 ] }, { [ 5, 6 ], [ 7, 8 ] } )
( { [ 9, 0 ], [ 1, 2 ] }, { [ 3, 4 ], [ 5, 6 ] } )
Matheus Moreira
  • 17,106
  • 3
  • 68
  • 107
0

Not looking to give away the farm here, but this is an example of how I look at multidimensional arrays in PHP.

$map[room][x][y][z][id][photopath][flag1][flag2]

I imagine what it would look like as a point in 3D space, then I just add sorting attributes. Here, imagine you're playing Doom 3. Each map is divisible into rooms, which have pixels with x, y, and z coordinates. Each of those points can have an object id (monster, item, etc.) associated with it. I've added more attributes for my application, but this is basically it. A point in the array doesn't necessarily have to be geometrically accurate; it can have any meaning. Whether this is similar to what other people do, I don't know. I do know that using the gd graphics library would make a nice visualizer for multidimensional arrays on the fly, but I didn't get to that project last time I was working for this client.

0

Visualize a 4D array as a 1D array of cubes. A 5D array as a 2D array of cubes. And a 6D array as a 3D array of cubes, or a cube of cubes. A 7D array as a 1D array of cubes of cubes, etc...

Benjamin Lindley
  • 101,917
  • 9
  • 204
  • 274
0

Ignoring whether these dimensions are neeeded, why not just envision a 4D array as a 1D array (line) of "cubes". (ie: an 1D array where each element points to a 3D cube). This can be scaled up as needed (ie: 2D surface where each element points to a cube). This of course isn't how a hypercube would 'look', but that isn't required.

Ivan K
  • 1
0

tabs :)

tabs of 3 dimensional data gives you 4 dimensions, tabs of tabs gives you n dimensional.

not thats necessarily the best way to visualize it. Also not good for rotating in any of the dimensions.

but then, it depends what you are trying to visualise

RGB for instance can be turned into a 2D map and then projected onto a cube, giving you 4d information

Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156