views:

262

answers:

9

An Array ( a row of elements ):

[ ][ ][ ][ ][ ][ ]

A 2-D Array ( a table ):

[ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ]

A 3-D Array:

//Imagine the above table as a cube ( a table with depth )

How does one visualize a 4-D array?

The closest I can come is multiple cubes, so for int[,,,] [5,10,2,7] would be cube 5, row 10, column 2, layer(depth) 7.

I'm not sure if this is the best way to visualize a 4-D array, though... and I'm not sure it's the best way to teach it... however it does have the advantage of being extensible ( a row cubes, a table of cubes, a cube of cubes ( 6-d array )

Cubes through time is another way that I can think of it.

Am I on the right track here?

+2  A: 

I can't draw it here, but visualize it as a line (or array) of cubes.

Another way is to first take your cube representation for a three-dimensional array. Now replace the cube in your mind with a child's wooden block, and line up several of the blocks next to each other.

Joel Coehoorn
+4  A: 

That's how I would teach it: a row of cubes. The position (or cube number) on this row is the 4th dimension.

And if you want 5-dimensions, now picture columns and rows - of cubes!

For 6 dimensions, picture the rows and columns of cubes (as for 5 dimensions), and now add "layers" of these rows and columns.

...For 7 dimensions, imagine all of the above - contained in cubes in a single row! ;)

Yup, it's cubes all the way down.

FrustratedWithFormsDesigner
boxes within boxes within boxes within...
Atømix
@Atomiton: Exactly. I see this pattern in datawarehouses.
FrustratedWithFormsDesigner
A: 

Two nice multidimensional visualizations, neither specific to four dimensions, are Parallel Coordinates and Table Lens.

Carl Manaster
A: 

Hypercube! But really, if you need a visualization, assume that each box that you've created from the 3D array now has an array within in. Kinda like string theory multi-dimensional ideas.

Michael Dorgan
+1  A: 

Visualizations in more than three dimension will not be very intuitive - no matter how hard you try. But you are on the right track - time-varying objects are a common method to visualize higher dimensional data.

A three dimensional object can be visualized with the time-varying intersection of the object with a plane while the object moves through the plane - for example a sphere passing through plane shows as a circle growing from a point to disc with the same radius as the sphere and shrinking to a point again.

The same can be done with four dimensional objects. They are visualized as the intersection of the object with a fixed three dimensional space while the object moves along the fourth dimension.

Daniel Brückner
This explanation reminds me of the book "Flatland". A very interesting read, for sure.
Atømix
+3  A: 

If you're trying to display output of a program for end users, then you are on the right track.

If you're trying to teach it, I'd briefly use that method, and then I'd go into depth explaining how the computer keeps them all in contigious memory -- http://webster.cs.ucr.edu/AoA/Windows/HTML/Arraysa2.html. I think this is the best way to understand it.

Nate Bross
+1! Wow! Great resource! Considering memory is linear on the stack, that link is fantastic! This is the kind of extra content that I was hoping this question would generate.
Atømix
+1, that's a great link.
FrustratedWithFormsDesigner
+1  A: 

It depends on what kind of data you're trying to visualize. For some situations I have had before 2D/3D image + RGB color worked fine. 2D picture forms two dimensions and Red, Green, Blue channels of color that is used to paint the point add another 3 dimensions.

For example take a look at normal maps used in game development. It visualizes a surface (2D) with a normal vector at each point (3D). Vectors are denoted with color components x~red, y~green, z~blue shifted on 127 to be able to store negative values.

nailxx
A: 

One visualization would be the maps from one surface to another surface. Imagine your hands hovering over different points on a table: any time you move either hand you get an entirely different value.

Charles
+1  A: 

Visualizing 3 dimensions as cubes and 4 dimensions as a line of cubes makes sense, but as you can see it's difficult to extend. The way that I usually think about it is to force the visualization into 2 dimensions. This is usually the easiest way to think of how arrays are stored in C, for example. A 2-dimensional array is really just an array of pointers to more arrays or, an array of arrays. Thinking of it this way comes in handy too if you really are forced to try and present 3+ dimensional data in a 2-dimensional format like a spreadsheet. Extra dimensions must be added as columns within columns or rows within rows.

Actually visualizing it hurts your eyes quickly, but at least it can be drawn on a chalkboard and it doesn't require a whole lot of imagination to add additional dimensions.

1-Dimensional (Array)

[] [] [] []

2-Dimensional (Array of Arrays)

[ [] [] ]  [ [] [] ]  [ [] [] ]  [ [] [] ]

3-Dimensional (Array of Arrays of Arrays)

[  [ [] [] ]  [ [] [] ]  ]   [  [ [] [] ]  [ [] [] ]  ]
Jelly
My eyes! I don't think 3D is any less extensible than 2D. row, table, cube. row of cube, table of cube... etc. You can get to 6 dimensions ( cube of cube ) before it gets scary. With brackets... you have brackets, brackets of brackets, brackets of ( brackets of brackets ), brackets of brackets of ( brackets of brac... etc. However I will say that it's easier to draw on a 2D medium ( chalkboard ) for sure.
Atømix
@Atomiton: Ha, fair enough. Which one works for you probably depends a little bit on the person. Boxes within boxes really isn't any different than bracket boxes within bracket boxes, but for some reason the cube image makes my head hurt more - boxes infinitely consuming more space that isn't there... I need it to be something I can make concretely happen to get a good grasp.
Jelly
@Jelly. I think you'd enjoy the book Flatland. A fascinating look at what it would be like for people who lived in a 2-dimensional world.
Atømix
@Atomiton: It has actually been on my to-read list for a long time. Your previous comment about Flatland reminded me that I should pick up a copy!
Jelly
@Jelly. If you have an iPhone/iTouch, it's available free ( i believe it's in the public domain ) with the "Classics" app. I think that app was free.
Atømix