Jump to content

3D Array


kylomas
 Share

Recommended Posts

There is no "real" football in the US today so it's a nice afternoon to get your mind bent. And the bender is 3D arrays.

I understand the theory of it, an index of 2D arrays. I also understand some possible applications, calendar (day, month, year), etc.

What I don't understand is the "how" (and maybe the "why") of it.

Consider this:

A group of people (one dimension)

with access to resources (another dimension)

with each resource having permissions by person (a third dimension)

This is the problem that started me down the 3D path. I HAVE considered associating 2D arrays and database solutions (which seems most appropriate).

So my long winded question is simple, how do you declare and initialize a 3D array in AI (I've been searching and playing with this for about 2 hours). More importantly, what are your thoughts on choosing a solution strategy, given the basics of the problem?

Gotta go pick up the wife from a poker all-nighter, look forward to reading your replies!

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Have you used a 1d or 2d array? Just do the same but with 3 dimensions.

$avArray1d[1]
$avArray2d[1][1]
$avArray3d[1][1][1]

If you are still unsure about anything, there's a Array Tutorial in the wiki you could look at :idiot:

More importantly, what are your thoughts on choosing a solution strategy, given the basics of the problem?

Sorry, but I'm too confused by your description of the "second" and third" -dimension to answer that.

A group of people (one dimension)

with access to resources (another dimension)

with each resource having permissions by person (a third dimension)

Person? Permissions? Resource? :)

Maybe a drawing or something would help ;)

Link to comment
Share on other sites

admiralalex, daddy,

yes, I use 1 and 2D array extensively.

I've read and re-read everything on this forum and Wiki concerning arrays. Also many discussions in C and VB.

I understand how to declare the 3D array, but, not how to initialize it in the declaration. Can probably figure out how to populate it with nested loops but that would detract from all the fun :)

EG APP:

1D 2D 3D

jon file1 yes

joe file1 no

joe pgm1 yes

john pgm1 no

As I said, there's alot of ways to skin this cat, but I was feeling too good so thought I would tackle a 3D array ;)

thanks, and "Go Pack",

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

yes, JohnOne, it is likely that I am wasting everyone's time as this is not something commonly done. Now it's going to bug me till I can code something in 3D (talk about stubborn) :)

thanks,

admiralalkex

daddy

JohnOne

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

I understand how to declare the 3D array, but, not how to initialize it in the declaration. Can probably figure out how to populate it with nested loops but that would detract from all the fun :)

EG APP:

1D 2D 3D

jon file1 yes

joe file1 no

joe pgm1 yes

john pgm1 no

First, that is not a 3D array data set. It is only 2D (like a spreadsheet with 4 rows/3 cols). But here are some examples for initializing arrays at declaration:
#include <Array.au3>

Global $sTxt = ""

; 1D array
Global $aOne[4] = ["jon", "joe", "jim", "john"]
_ArrayDisplay($aOne, "$aOne")

; 2D array
Global $aTwo[4][3] = [["jon", "file1", "yes"],["joe", "file2", "no"],["jim", "pgm1", "yes"],["john", "pgm2", "no"]]
_ArrayDisplay($aTwo, "$aTwo")

; 3D array
Global $aThree[3][5][3] = [[["Red Team", "", ""], ["jon", "file1", "yes"],["joe", "file2", "no"],["jim", "pgm1", "yes"],["john", "pgm2", "no"]], _
        [["Blue Team", "", ""], ["kevin", "file3", "yes"],["kari", "file4", "no"],["keith", "pgm3", "yes"],["karl", "pgm4", "no"]], _
        [["Gold Team", "", ""], ["lenny", "file5", "yes"],["lawrence", "file6", "no"],["louis", "pgm5", "yes"],["larry", "pgm6", "no"]]]
For $a = 0 To UBound($aThree) - 1
    $sTxt = $aThree[$a][0][0] & @LF & "--------------------------" & @LF
    For $b = 1 To UBound($aThree, 2) - 1
        For $c = 0 To UBound($aThree, 3) - 1
            $sTxt &= "[" & $a & "][" & $b & "][" & $c & "] = " & $aThree[$a][$b][$c] & @TAB
        Next
        $sTxt &= @LF
    Next
    ConsoleWrite($sTxt & @LF)
Next

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

When I converted a JS code to AutoIt I used a 3D array to save all needed values.

A 3D array is something like a 3D cube.

If you want, you can hava a look to (example 24).

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

psalty,

That is EXACTLY what I thought (a simple row/col 2D array) and why I am having trouble seeing this concept mentally. Thanks for the syntax, that's where I was going but did NOT have the bracketing correct.

I am going to look at UEZ's "real life" example to try to bridge between theory and practice.

Thanks to all that took the time to respond.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

psalty, UEZ,

I see it now :)

UEZ alluded to a ribic's cube. When I saw the initialization code it began to make sense. I ran the code and seeing the results married the idea to the practicality of the idea.

A quote once heard:

"I am standing in a field,

in the bright sunlight,

amoung the flowers,

on a steaming pile of cow shit"

- author unknown (but probably worked with 3D arrays)

Again,

thanks

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

There is technically no limit to the dimensions of an array, but after a few dimensions it gets hard to remember what you were trying to do, and some other way might be easier to comprehend.

Dim $warehouseitem(aisle,row,column,warehouseid,cityid,countryid,planetid,paralleluniverseid)

$warehouseitem(1,2,2,7,5,2,5,5) = 20

,

Also, declaring an empty multidimensional array rapidly consumes memory.

Dim $item(10,10,10,10,10,10,10) ... 10,000,000 items

If $item is a 256 byte string, then the array needs 2.3 gigabytes of memory, even containing no data

Note that the number of items in this example is "small".. a multidimensional array with 100's of items per dimension will be insanely huge.

Edited by Javik
Link to comment
Share on other sites

There is technically no limit to the dimensions of an array, but after a few dimensions it gets hard to remember what you were trying to do, and some other way might be easier to comprehend.

There is a limit of 64 subscripts (dimensions) in AutoIt (and your examples are NOT in AutoIt syntax).

Also, declaring an empty multidimensional array rapidly consumes memory.

Dim $item(10,10,10,10,10,10,10) ... 10,000,000 items

If $item is a 256 byte string, then the array needs 2.3 gigabytes of memory, even containing no data

Note that the number of items in this example is "small".. a multidimensional array with 100's of items per dimension will be insanely huge.

Not exactly. It is true that Dim $vArray[10][10][10][10][10][10][10] (seven subscripts) produces 10M elements, but AutoIt initializes them as null string variants so the memory footprint will not become huge until you start putting data in the cells. You could also create a simple 1D array with only three elements and put a 1GB string in each element to cause the same issues.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

When I wish to visualize a 4 dimensional array, I just think of it as an array of rubix cudes. So $my4DArray[3][3][3][3] would contain three Rubux Cubes, and $my5DArray[3][3][3][3][3] would contain a 3x3 grid in which each field contains a Rubix Cube. If that makes any sense. There are also other ways to visualize this.

Edited by czardas
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...