is there any solution to make a array to a unique array in attribute wrangle ?
for example i have an array {0,4,4,5,6,7,5,6,5,5} and i want to convert that to {0,4,5,6,7} ,
thanks
How to make a unique array in attribute wrangle ?
5554 6 3- vrman
- Member
- 39 posts
- Joined: Sept. 2013
- Offline
- BabaJ
- Member
- 2036 posts
- Joined: Sept. 2015
- Offline
In a wrangle set to detail:
i[]@List = {1,8,8,2,7,3,8,4,8,6,7,1,1};
int Count, Count_A;
for(Count = 0; Count < len(i[]@List); Count++)
{
for(Count_A = 0; Count_A < len(i[]@List); Count_A++)
{
if( (i[]@List[Count] == i[]@List[Count_A]) && (Count != Count_A) )
{
removeindex(i@List, Count_A);
}
}
}
Edited by BabaJ - Nov. 6, 2018 08:45:06
- Andr
- Member
- 900 posts
- Joined: Feb. 2016
- Offline
If u want to dig python, this might be a good chance to try. (it was a good chance for me as I'm python novice)
Basically you convert your array to a “set” (which is an “unordered collection of distinct objects”) and then you convert it back to an array (array and list is the same thing in python)
reference here:
https://stackoverflow.com/questions/7961363/removing-duplicates-in-lists [stackoverflow.com]
I guess in this particular case the performance is the same as you would do it in vex (which can't be parallelized in this case).
Basically you convert your array to a “set” (which is an “unordered collection of distinct objects”) and then you convert it back to an array (array and list is the same thing in python)
myarray = [1, 2, 3, 1, 2, 5, 6, 7, 8] list(set(myarray))
reference here:
https://stackoverflow.com/questions/7961363/removing-duplicates-in-lists [stackoverflow.com]
I guess in this particular case the performance is the same as you would do it in vex (which can't be parallelized in this case).
Edited by Andr - Nov. 6, 2018 10:45:18
- PavelK
- Member
- 1 posts
- Joined: July 2014
- Online
///////////////// // VEX Function: unique values of array function int[] fn_arrayuniqueval (int arr[]) { int tmp[] = {}; foreach(int src; arr) { int i =0; foreach(int itm; tmp) if (src == itm) i++ ; if (i == 0) append(tmp, src); } return arr = tmp; } ///////////////// // Custom Code i[]@List = {1,8,8,2,7,3,8,4,8,6,7,1,1}; @List = fn_arrayuniqueval(@List);
- animatrix_
- Member
- 4495 posts
- Joined: Feb. 2012
- Offline
Hi,
You can also do it like this:
You can also do it like this:
function int [ ] uniqueelements ( int arr [ ] ) { int result [ ] = array ( ); foreach ( int i; arr ) if ( find ( result, i ) < 0 ) append ( result, i ); return result; } int arr [ ] = { 0, 4, 4, 5, 6, 7, 5, 6, 5, 5 }; i[]@result = uniqueelements ( arr );
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 | animatrix2k7.gumroad.com
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
- Andr
- Member
- 900 posts
- Joined: Feb. 2016
- Offline
It's not what op was looking for, but I post it anyway for the future reader who might land here from a forum search.
There is the a nice handy function uniquevals() that “returns the set of unique values across all values for an int or string attribute”.
I wasn't aware of its existence till very recently…
There is the a nice handy function uniquevals() that “returns the set of unique values across all values for an int or string attribute”.
I wasn't aware of its existence till very recently…
Edited by Andr - Aug. 20, 2020 06:42:33
- Sweetener
- Member
- 59 posts
- Joined: Nov. 2014
- Offline
-
- Quick Links