How can I conceptualize an array with more than three dimensions?
I just learned about arrays but can't c开发者_运维技巧onceptualize arrays with more than three dimensions.
Imagine the following:
- Letters on the line of a book
- Lines on a page of a book
- Pages of the book
- Books in a bookshelf
- A room full of bookshelves
- House full of rooms
- A street with a number of houses
- A town with streets
- A Country with towns
- A planet with countries
- A universe full of planets
- And finally, a big array of universes.
Viola, a 12 dimensional array.
Imagine a series of 3-dimensional cubes, one after another.
You can also think of it as a single 3D cube evolving over discrete intervals of time.
I find these helpful if you want a mental model that fits into the usual spatial (plus time) system, i.e. something whose dimensions you can visualize all at once in the physical world.
Very few people can grasp what the 4th spatial dimension would look like. Here are two pointers if you want to try to understand:
- wikipedia
- a very good video tutorial
Multidimensional arrays don't need to be conceptualised as rectangles, cubes, etc. There is another way of looking at them. A 2-dimensional array is a 1-dimensional array of equal-sized 1-dimensional arrays. A 3-dimensional array is a 1-dimensional array of 2-dimensional arrays. Etc. You can visualise the nested arrays as being all horizontal, or all vertical, or alternately horizontal and vertical - whatever you like.
If by "conceptualize" you mean "imagine", then that's fine. We, as 3D beings, can't really grasp higher dimensional stuff (most of us, anyways).
It's the same with quaternions, which work in the 4D number space, or with the clipping space in graphics, which is used to bring 3D models onto our 2D screen, with a detour through the 4th dimension. Even though most programmers don't really understand that stuff, we still use it just fine. The most important thing is though, not trying to question how that works. Else you'll feel pretty lost in all the dimensional theories (at least I do).
Now, like said in the comments, 4D arrays are very very sparse from what I can tell. If you really need one, it won't be as a 4 dimensional shape, but rather as a list of 3 dimensional shapes. or a 2D array of 2D arrays. Don't take the "dimension" part as "spatial dimension". Just think of multi-dimensional arrays like "after one pair of square brackets []
, there will be another. And another. And so on, until you the number of []
and the number of dimensions of the array match. So they're more like lists of lists of lists of... :)
Let's say you got a bookshelf, from afar you only see 2 dimensions. Now as you draw nearer to the shelf you want (arr[x][y]
), you find, that there are still subdivisions in each shelf, a bookshelf of bookshelves. :)
Hope that cleared things up a bit. Cheers.
Go look at one of the larger tables in the nearest relational database. That table is an array that just happens to be indexed by column name rather than explicit numbers; the columns are clearly a finite set so they can be put into one-to-one correspondence with the non-negative integers and this mapping gives you your more familiar array dimensions.
精彩评论