Find the position within an array larger than 3D (New Features)

by lrcvs, Tuesday, May 01, 2012, 22:16 (2055 days ago)

Question:

How to find the position that has an element of an array / vector / multidimensional array, using a mathematical formula?

For example, in a 2D array of 4 x 4

A B C D
E F G H
I J K L
M N O P

A 1D 2D array = Array = ABCDEFGHIJKLMNOP
Position = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16. Ok!

Then, the position Rowx = 3, colx = 3, position = 11 & content = K

Formula: ((Rowx -1) * col) + colx

= ((3 - 1) * 4) + 3 = Position 11 = element = K

:::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::

Now in a 3D array = 4 x 4 x 4

1D = 3D = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ... 60 61 62 63 64
POSITION 63 = CONTENT = 63

level 1

1 2 3 4
5 7 7 8
9 10 11 12
13 14 15 16

level 2

17 18 19 20
21 22 23 24
25 26 27 28
29 30 31 32

level 3

33 34 35 36
37 38 39 40
41 42 43 44
45 46 47 48

level 4

49 50 51 52
53 54 55 56
57 58 59 60
61 62 63 64

Example: Row 4 x column 3 x Level 4 = 4x3x4 = 63 Position 63 = Element

3D position pa Formula:

((Rowx - 1) * col) + colx + ((rows * cols) * (level -1))

((4 - 1) * 4 * 4) + 3 + ((4 * 4) * (4 - 1)) = POSITION 63 = content = 63

:::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::

So my question is:

What is the formula to find the position within an array larger than 4 or 5 or 20?

Thanks"

Find the position within an array larger than 3D

by Jim ⌂ @, Russell, KY, Wednesday, May 02, 2012, 02:52 (2055 days ago) @ lrcvs

M...

for 2 D assuming d1 and d0 as the dimensions and a1 and a0 are the array index

the formula i2d = (a1-1) * d0 + (a0-1) would convert to 1D

3d d2, d1, d0 and a2, a1, a0 would be

i3d = (a2-1) * d1 * d0 + (a1-1) * d0 + (a0-1) - or -
i3d = (a2-1) * d1 * d0 + i2d


4d d3, d2, d1, d0 and a3, a2, a1, a0 would be

i4d = (a3-1) * d2 * d1 * d0 + (a2-1) * d1 * d0 + (a1-1) * d0 + (a0-1) - or -
i4d = (a3-1) * d2 * d1 * d0 + i3d

I think this would be a general (recursive) definition (in my own screwy notation.

i{N}d = (a{N-1} - 1) * PRODUCT(d{N-2} ... d{0}) + i{n-1}d

Find the position within an array larger than 3D

by lrcvs, Saturday, May 05, 2012, 08:39 (2052 days ago) @ Jim

I understand means well.

But I do not understand is the concept of fourth, fifth, sixth, .... dimension.

For example: Z = [5 4 3 2]

mathematically speaking it would be 5 * 4 * 3 * 2 = 120 elements.

But 5 * 4 = X * Y = level 1 = 20 elements in each level.

20 * 3 = 20 * Z is the number of 3D or level 3 = 60 items.

So far, so good.

Now we have the 4D = 2.

I understand that at level 3, the last layer, and each element has an extension of 2 more items of the fourth dimension.

So I think and say 20 elements of the last level * 2 extensions more = 40 elements.

I still think if 3D = 60 items + 40 items in the fouth dimension = 100 items.

No item that is the 120 mathematically speaking.

What is your concept of the following dimensions to 3D?

(the fourth, fifth, sixth ... dimension)

Find the position within an array larger than 3D

by lrcvs, Saturday, May 05, 2012, 13:27 (2052 days ago) @ lrcvs

Hey, hey, hey, STOP.

I have found my error in 4D.

It is a error of conception dimendional.

Well, let's let W = (5 * 4 * 3 * 2) = 120 elements, Ok!
w = (x * y * z * "D")
x = 1D
y = x * y = 2D
z = x * y * z = 3D
D = number of times that repeats the block x, y, z

Let's see:
w = (5 * 4 * 3 * 2) = 120
We see that "2" is the number of times
Now comes my error of conception,
I have assumed that 4D was an extension of 3D, that was my error of conception.

As we see from my calculation / deduction wrong in my post:
:::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::
We have now in the 4D = 2.
I Understand That at level 3, the last layer,
and has an element Each extension of 2 more items of the fourth dimension.
So I think 20 elements of the last level * 2 = 40 elements more extensions.
I still think if 3D = 60 items + 40 items in the fouth dimension = 100 items.
That item is not the 120 Mathematically speaking.

This is a ERROR!!!
:::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::

... Then the fourth dimension (4D) are the times you repeat the block: x, y, z.

Now, by extension ...
we know what they mean the fifth, sixth, seventh, eighth,..... dimensions:

An example:
w = (2 * 2 * 2 * 2 * 2) = (a b c d e)
a * b * c = 2 * 2 * 2 = 8 = 3D starting block

8 * d (d as we have said is the number of times to repeat xyz) then 8 * 2 = 16 elements to the fourth dimension

we ...

16 * e ("e" also indicates the number of times to repeat the previous block, xyz + d)
16 * 2 = 32 total elements in W (2 * 2 * 2 * 2 * 2)


I believe that I have understood the concept of multidimensional array.

Thank you all for your interest in explaining the concepts of multidimensional array.

RSS Feed of thread
powered by my little forum