Combining arrays of different lengths into another array

   1836   6   2
User Avatar
Member
6 posts
Joined: 7月 2022
Offline
Hello
i got a a couple of different sized arrays of ptnumbers that i want to combine into one array to access them later

int num0[]=  {55, 56, 5, 64, 115, 68 };
int num1[] = {35,5, 115};
int num2[] = {2, 8, 111, 119};
int num3[] = {25,3,8,41,37,59,63,118,113};

int arr[] = array( num0, num1, num2, num3 );
i[]@arr = arr;

---
if i run the above code i get {0,0,0} as contents of the array
I guess that has to do with my declaration as i@

---

I can write them all into array as one with append in
long list {1,2,3,4,5,6,7,8,9}

but i want to keep them
seperate as arrays( {{1,2,3}, {4,5,6,7}, {8,9,10,11,12} ....})

so i can run a foreach() over the arr

How would i do that?

--

Thanks in advance and for help and time.
Edited by florianpruetz - 2023年10月17日 05:46:22
User Avatar
Member
4703 posts
Joined: 2月 2012
Offline
Hi,

VEX doesn't have arrays of arrays (jagged arrays) but you can emulate them using 2 arrays: one flat array for the elements, another one for the start of each array for example.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
6 posts
Joined: 7月 2022
Offline
Ok thanks animatrix, always helpful!

What made me go down that path was also this helpdocument which uses what i need.

https://www.sidefx.com/docs/houdini/vex/arrays.html [www.sidefx.com]

The first code example has this

av = array( {1,0,0}, vector(nrandom()), t, texclr, {.5,0,0});


Isn´t that sort of what i need, an array stuffed with more arrays?
User Avatar
Member
4703 posts
Joined: 2月 2012
Offline
florianpruetz
Ok thanks animatrix, always helpful!

What made me go down that path was also this helpdocument which uses what i need.

https://www.sidefx.com/docs/houdini/vex/arrays.html [www.sidefx.com]

The first code example has this

av = array( {1,0,0}, vector(nrandom()), t, texclr, {.5,0,0});


Isn´t that sort of what i need, an array stuffed with more arrays?

Thats only an array of vectors. Array of arrays doesn't even work if you try to hide them with a struct, i.e. an array of structs. SESI is aware of this limitation.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
899 posts
Joined: 2月 2016
Offline
I guess a dictionary attribute could work for storing multiple arrays?
Edited by Andr - 2023年10月18日 09:58:02
User Avatar
Member
4703 posts
Joined: 2月 2012
Offline
Andr
I guess a dictionary attribute could work for storing multiple arrays?

Yes that would be a workaround but it's horribly inefficient in performance compared to using 2 arrays the way I described.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
6 posts
Joined: 7月 2022
Offline
Oh Yes the dictionary works!
As for the performance mentioned by @animatrix_, my setups arent that performative anyway...
  • Quick Links