# Visualizing multi dimensional array

Page 1 of 1

## 4 Replies - 841 Views - Last Post: 16 January 2013 - 11:32 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=307189&amp;s=657f1af5c942e418f3b3abb9ac2914fd&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 rnty

Reputation: 19
• Posts: 178
• Joined: 14-August 12

# Visualizing multi dimensional array

Posted 14 January 2013 - 07:09 AM

How do I visualize arrays with 3 or 4 dimensions?
Is This A Good Question/Topic? 0

## Replies To: Visualizing multi dimensional array

### #2 Skydiver

• Code herder

Reputation: 4371
• Posts: 14,100
• Joined: 05-May 12

## Re: Visualizing multi dimensional array

Posted 14 January 2013 - 08:25 AM

What story or message are you trying to emphasize to the viewer?

Or do you merely need a way for the viewer to browse through the data?

### #3 rnty

Reputation: 19
• Posts: 178
• Joined: 14-August 12

## Re: Visualizing multi dimensional array

Posted 14 January 2013 - 10:02 PM

I want to use it to solve problems related to multi-dimensional arrays.
eg.
int a[2][2][2]={1,2,3,4,5,6,7,9};
What is the value of a[1][0][1]?
Thanks

### #4 jjl

• Engineer

Reputation: 1130
• Posts: 4,686
• Joined: 09-June 09

## Re: Visualizing multi dimensional array

Posted 14 January 2013 - 10:12 PM

2D arrays can be conceptually visualized as a 2D grid of values. Adding a dimension to a 2D array will result in a 3D array, which can be visualized as a cube of elements (remember that data in memory is physically layed out continuously).

Quote

Quote

int a[2][2][2]={1,2,3,4,5,6,7,9};
What is the value of a[1][0][1]?

The value of a[1][0][1] can be conceptually represented as the coordinate (1,0,1) in the 3D cube of values.

This might help clarify

### #5 Mrk

Reputation: 29
• Posts: 66
• Joined: 03-December 09

## Re: Visualizing multi dimensional array

Posted 16 January 2013 - 11:32 AM

rnty, on 14 January 2013 - 08:09 AM, said:

How do I visualize arrays with 3 or 4 dimensions?

Of course, the array is laid out in memory in a contiguous fashion, regardless of how many dimensions.
(The following symbols are simply used to represent a space: . ' ,).

int a[2] = (1,2)

int a[2][2] = (1,2...3,4)

int a[2][2][2] = (1,2...3,4) ..... (5,6...7,8)

int a[2][2][2][2] = (1,2...3,4) ..... (5,6...7,8) '''''''''''''' (9,10...11,12) .....(13,14...15,16)

The leftmost indice makes the largest course selection, and the rightmost indice zeros in on the single data element of interest. Of course, keep in mind indices start at 0:

a[0] = (1,2)

a[1][x] = (1,2...3,4) // x would then select 3 or 4;

a[0][x][y] = (1,2...3,4) ..... (5,6...7,8) // x would select either 1,2 or 3,4 and y would zero in on the final digit;

a[1][x][y][z] = (1,2...3,4) ..... (5,6...7,8) ''''''''''''''' (9,10...11,12) ......(13,14...15,16)

a[1][0][1][0] = 11
a[0][0][0][0] = 1
a[0][x][y][z] = (1,2...3,4) ..... (5,6...7,8) '''''''''''''' (9,10...11,12) .....(13,14...15,16) // leaving the leftmost indice zero would cause this array to be only a 3d array using just x,y and z.

Watch this progression:
a[1][0][0][1] = 10:

a[1][x][y][z] = (1,2...3,4) ..... (5,6...7,8) '''''''''''''' (9,10...11,12) .....(13,14...15,16)

a[1][0][y][z] = (1,2...3,4) ..... (5,6...7,8) '''''''''''''' (9,10...11,12) .....(13,14...15,16)

a[1][0][0][z] = (1,2...3,4) ..... (5,6...7,8) '''''''''''''' (9,10...11,12) .....(13,14...15,16)

a[1][0][0][1] = (1,2...3,4) ..... (5,6...7,8) '''''''''''''' (9,10...11,12) .....(13,14...15,16)

Also, if you were to toggle sequentially through an array, the right most indice would increase the fastest while the leftmost indice would increase the slowest, just like on a car's odometer.

This post has been edited by Mrk: 16 January 2013 - 12:15 PM