1. 3 dimension array
- Posted by darceman <darce at ffi.com> Aug 21, 2002
- 417 views
What is the code needed to create a 3 dimensional array? In Basic it is a simple Dim somearray(a,b,c). I assume that I can take the code for 3 dimensions to configure one for 4 and possible 5 dimensions. The arrays will strictly house integers and will initially be filled with zeroes. The multiple dimensions are needed to access unique number combinations representing time, space and values. Thanks
2. Re: 3 dimension array
- Posted by ajm.tammer at quicknet.nl Aug 21, 2002
- 399 views
3 dim array: {{{,,,,},{...}},{{,,,},{,,,}},{{,,,},{,,,}}} that's it i guess Darceman a@t
3. Re: 3 dimension array
- Posted by "C. K. Lester" <cklester at yahoo.com> Aug 21, 2002
- 388 views
> What is the code needed to create a 3 dimensional array? In Basic it is > a simple Dim somearray(a,b,c). I assume that I can take the code for 3 > dimensions to configure one for 4 and possible 5 dimensions. > > The arrays will strictly house integers and will initially be filled > with zeroes. The multiple dimensions are needed to access unique number > combinations representing time, space and values. First, you'll probably want to stop thinking in terms of arrays in the traditional sense, and start grasping for the sequence. I think. hmmmmm. Here's what a two dimensional sequence looks like: { { One, Two, Three, Four }, { Two, Two, Three, Four }, { Three, Two, Three, Four } } myArray[3] = {Three, Two, Three, Four} myArray[3][4] = Four Here's what a three dimensional sequence looks like: { { {One1, Two, Three, Four }, { Two1, Two, Three, Four }, { Three1, Two, Three, Four } }, { {One2, Two, Three, Four }, { Two2, Two, Three, Four }, { Three3, Two, Three, Four } } } myArray[2] = { {One2, Two, Three, Four }, { Two2, Two, Three, Four }, { Three3, Two, Three, Four } } myArray[2][3] = { Three3, Two, Three, Four } myArray[2][3][4] = Four There are libraries that will help you deal with sequences as arrays, and even using a database program (like the EUPHORIA database system) would be reasonable. I think. -ck
4. Re: 3 dimension array
- Posted by Juergen Luethje <jluethje at gmx.de> Aug 21, 2002
- 379 views
darceman <darce at ffi.com> wrote: > What is the code needed to create a 3 dimensional array? In Basic it is > a simple Dim somearray(a,b,c). I assume that I can take the code for 3 > dimensions to configure one for 4 and possible 5 dimensions. > The arrays will strictly house integers and will initially be filled > with zeroes. The multiple dimensions are needed to access unique number > combinations representing time, space and values. > Thanks a = 3 b = 7 c = 4 somearray = repeat(repeat(repeat(0,c),b),a) demo_val = 0 for i = 1 to a do for j = 1 to b do for k = 1 to c do demo_val += 1 somearray[i][j][k] = demo_val end for end for end for print(1, somearray) Regards, Juergen
5. Re: 3 dimension array
- Posted by "C. K. Lester" <cklester at yahoo.com> Aug 21, 2002
- 377 views
> > What is the code needed to create a 3 dimensional array? In Basic it is > > a simple Dim somearray(a,b,c). I assume that I can take the code for 3 > > dimensions to configure one for 4 and possible 5 dimensions. > > > The arrays will strictly house integers and will initially be filled > > with zeroes. The multiple dimensions are needed to access unique number > > combinations representing time, space and values. > > > Thanks > > > a = 3 > b = 7 > c = 4 > somearray = repeat(repeat(repeat(0,c),b),a) This will need to be made into a recursive function, I'm sure... :)
6. Re: 3 dimension array
- Posted by Juergen Luethje <jluethje at gmx.de> Aug 21, 2002
- 383 views
darceman <darce at ffi.com> wrote: > What is the code needed to create a 3 dimensional array? In Basic it is > a simple Dim somearray(a,b,c). I assume that I can take the code for 3 > dimensions to configure one for 4 and possible 5 dimensions. > The arrays will strictly house integers and will initially be filled > with zeroes. The multiple dimensions are needed to access unique number > combinations representing time, space and values. > Thanks Grmpf ... Topica slurred parts of my previous message. It should read like this (if this message gets through completely): --==--==--==--==--==--==--==--==--==--==--==--==--== integer a, b, c, demo_val sequence somearray a = 3 b = 7 c = 4 somearray = repeat(repeat(repeat(0,c),b),a) demo_val = 0 for i = 1 to a do for j = 1 to b do for k = 1 to c do demo_val += 1 somearray[i][j][k] = demo_val end for end for end for print(1, somearray) --==--==--==--==--==--==--==--==--==--==--==--==--== Regards, Juergen
7. Re: 3 dimension array
- Posted by Juergen Luethje <jluethje at gmx.de> Aug 21, 2002
- 381 views
C. <cklester at yahoo.com> wrote: >> > What is the code needed to create a 3 dimensional array? In Basic it is >> > a simple Dim somearray(a,b,c). I assume that I can take the code for 3 >> > dimensions to configure one for 4 and possible 5 dimensions. >> >> > The arrays will strictly house integers and will initially be filled >> > with zeroes. The multiple dimensions are needed to access unique number >> > combinations representing time, space and values. >> >> > Thanks >> >> >> a = 3 >> b = 7 >> c = 4 >> somearray = repeat(repeat(repeat(0,c),b),a) > This will need to be made into a recursive function, I'm sure... :) The example I gave works. Why "need to"? Regards, Juergen
8. Re: 3 dimension array
- Posted by "C. K. Lester" <cklester at yahoo.com> Aug 21, 2002
- 385 views
> >> a = 3 > >> b = 7 > >> c = 4 > >> somearray = repeat(repeat(repeat(0,c),b),a) > > > This will need to be made into a recursive function, I'm sure... :) > > The example I gave works. Why "need to"? In case he wants more than 3 dimensions (as he mentioned in his original post)...
9. Re: 3 dimension array
- Posted by Juergen Luethje <jluethje at gmx.de> Aug 21, 2002
- 395 views
C. <cklester at yahoo.com> wrote: >> >> a = 3 >> >> b = 7 >> >> c = 4 >> >> somearray = repeat(repeat(repeat(0,c),b),a) >> >> > This will need to be made into a recursive function, I'm sure... :) >> >> The example I gave works. Why "need to"? > In case he wants more than 3 dimensions (as he mentioned in his original > post)... I disagree for several reasons. 1) With the same method I used (_without_ recursion), you can create arrays with say 100 dimensions if you like, just by nesting repeat() 100 times, instead of 3 times. 2) It's not a matter of the number of dimensions one wants, the main question is, if a) the number of dimensions is known at "compile" time (then a "static" approach like mine will be OK for any number of dimensions), or b) if the number of dimensions is dynamically provided at runtime. 3) For case 2b), my approach does not work, but he didn't describe that situation in his question. And even in case 2b), recursion is not needed, simple iteration will be sufficient to dimension the array: --==--==--==--==--==--==--==--==--==--==--==--==--== sequence dim object somearray dim = {3,7,4} -- number and size of dimensions somearray = 0 for d = length(dim) to 1 by -1 do somearray = repeat(somearray, dim[d]) end for -- etc. --==--==--==--==--==--==--==--==--==--==--==--==--== Regards, Juergen
10. Re: 3 dimension array
- Posted by christian.cuvier at education.gouv.fr Aug 22, 2002
- 406 views
----- Original Message ----- From: "C. K. Lester" <cklester at yahoo.com> To: "EUforum" <EUforum at topica.com> Subject: Re: 3 dimension array > > > What is the code needed to create a 3 dimensional array? In Basic it is > > a simple Dim somearray(a,b,c). I assume that I can take the code for 3 > > dimensions to configure one for 4 and possible 5 dimensions. > > > > The arrays will strictly house integers and will initially be filled > > with zeroes. The multiple dimensions are needed to access unique number > > combinations representing time, space and values. > > First, you'll probably want to stop thinking in terms of arrays in the > traditional sense, and start grasping for the sequence. I think. hmmmmm. > > Here's what a two dimensional sequence looks like: > > { > { One, Two, Three, Four }, > { Two, Two, Three, Four }, > { Three, Two, Three, Four } > } > > myArray[3] = {Three, Two, Three, Four} > myArray[3][4] = Four > > Here's what a three dimensional sequence looks like: > > { > { > {One1, Two, Three, Four }, > { Two1, Two, Three, Four }, > { Three1, Two, Three, Four } > }, > { > {One2, Two, Three, Four }, > { Two2, Two, Three, Four }, > { Three3, Two, Three, Four } > } > } > > myArray[2] = > { > {One2, Two, Three, Four }, > { Two2, Two, Three, Four }, > { Three3, Two, Three, Four } > } > > myArray[2][3] = { Three3, Two, Three, Four } > > myArray[2][3][4] = Four > > There are libraries that will help you deal with sequences as arrays, and > even using a database program (like the EUPHORIA database system) would be > reasonable. > > I think. > > -ck > > > > Dear Darcman, Indeed, Ephoria has no array, it has sequences, as explained above. You may thi,k of sequences as trees, except that the root is hidden (it is the sequence container itself). If you want to create a 3-dimensional matrix m with zeroes, with initial item number p,q and r, you can use te following statement: m=repeat(p,repeat(q,repeat(r,0))) This is a sequence of p idntical sequences. Each of these is a sequence of q identical subsequences, each of which is a sequence of r zeroes. Type does not matter. Alter elements and layout as you wish. Regards. Chris
11. Re: 3 dimension array
- Posted by Juergen Luethje <jluethje at gmx.de> Aug 22, 2002
- 418 views
Hello Derek, cool idea to put this stuff into a function. Derek <ddparnell at bigpond.com> wrote: > 22/08/2002 12:03:07 PM, rforno at tutopia.com wrote: >> >> The repeat amount should not be a sequence, but it can be an atom, the floor >> of which is used to dimension the array. Marvellous Euphoria. Of course, no >> negative values. > Thanks Ricardo. Thus we get... > function DIMArray( sequence Dimension, object InitValue ) > sequence lNewArray So that the function works properly, when <InitValue> is an atom, <lNewArray> should be declared as object, shouldn't it? > if length(Dimension) = 0 then > return 0 > end if > lNewArray = InitValue > for i = length(Dimension) to 1 by -1 do > if atom(Dimension[i]) and Dimension[i] > 0 then > lNewArray = repeat(lNewArray, Dimension[i]) > else > return i > end if > end for > return lNewArray > end function > ---------- > Derek. Regards, Juergen
12. Re: 3 dimension array
- Posted by Derek Parnell <ddparnell at bigpond.com> Aug 22, 2002
- 395 views
----- Original Message ----- From: "Juergen Luethje" <jluethje at gmx.de> To: "EUforum" <EUforum at topica.com> Subject: Re: 3 dimension array > > Hello Derek, > > cool idea to put this stuff into a function. Well it does encourage "reuse" that way. > > function DIMArray( sequence Dimension, object InitValue ) > > sequence lNewArray > > So that the function works properly, when <InitValue> is an atom, > <lNewArray> should be declared as object, shouldn't it? > Yes, you are correct. Otherwise you would have to do something like ... if atom(InitValue) then lNewArray = {InitValue} else lNewArray = InitValue end if I'm not sure if there is any performance penalty in declaring it as object. ---------- Derek.