multi dimension array in max

thetechnobear's icon

say I want a 2d array in max e.g.X[3][4]=12
what are my options?

(I'm mainly interested where indexes are numeric, so hoping for a pretty fast fixed storage lookup, doesn't even need to be a sparse array - though could be)

as far as i can tell its:
a) put a list in a coll/table, and then index list.
b) use dict with a nested dictionary?
c) javascript?

(a) would is limited to a 2d, I could not do N dimensions e.g. X[3][2][10]=14
(b) seems nice, but a bit of overkill, and presumably not very good for performance, as it works with symbols.
c) I've not looked into, and not sure i want to add the complexity

have i missed any other options? where are preferred ways?
(whats the coll or table?)

can I pull coll/tables into other coll/tables?

thanks for any pointers
Mark

pdelges's icon

Maybe jit.matrix.

Rick's icon
Max Patch
Copy patch and select New From Clipboard in Max.

If your looking for examples, here's a coll version of a 2d 4x4 array.

Max Patch
Copy patch and select New From Clipboard in Max.

You could also do this patch with a preset obj

metamax's icon

Get familiar with jitter… It's quite the powerful little tool. You can use it purely for managing numbers and doing math. No bouncing basketballs or ducks required.

Anyway, here are a few max examples in the spirit as Rick's input.

Max Patch
Copy patch and select New From Clipboard in Max.

Miguel's icon

FTM is your friend and very efficient

- Miguel

thetechnobear's icon

thanks... lots to learn :)
I realised i could use a single dimension by calculating index (e.g. z*(X*Y)+x*Y+y), but was hoping for something that had appropriate messages (easier to read code)

Yup, I thought jit objects were for bouncing ducks :) so will take a more careful look obviously wrong - jit.matrix looks pretty ideal - any drawbacks? (given the number of options, is it 'heavy', i guess not if its used for video etc)

nth on coll, these looks like it could be what I'm after for 2d.

FTM, ah bumped into this the other day... looks interesting, but Im trying to stay vanilla max initially, just so I can grasp a better understanding of whats there - but will definitely add FTM to my list for looking at afterwards.

special thanks for the examples, very helpful seeing how these things work.