4 Replies - 494 Views - Last Post: 16 January 2013 - 11:32 AM Rate Topic: -----

#1 rnty  Icon User is offline

  • D.I.C Head

Reputation: 20
  • View blog
  • Posts: 145
  • 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  Icon User is offline

  • Code herder
  • member icon

Reputation: 3471
  • View blog
  • Posts: 10,706
  • 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?
Was This Post Helpful? 0
  • +
  • -

#3 rnty  Icon User is offline

  • D.I.C Head

Reputation: 20
  • View blog
  • Posts: 145
  • 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
Was This Post Helpful? 0
  • +
  • -

#4 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1072
  • View blog
  • Posts: 4,532
  • 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
Was This Post Helpful? 1
  • +
  • -

#5 Mrk  Icon User is offline

  • D.I.C Head

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

Re: Visualizing multi dimensional array

Posted 16 January 2013 - 11:32 AM

View Postrnty, 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

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1