Hi!
if I have a bunch of primitives with array values like this:
prim 0: [5, 15, 132, 8]
prim 1: [0, 3, 522, 5]
etc.
…how do I verify if a primitive array contains a common value as another primitive? In this case, they both have the value “5” therefore they should be place in a group.
-Olivier
primitive array: group if 2 primitives contains common array value
1709 4 0- olivierth
- Member
- 1012 posts
- Joined: April 2017
- Offline
- BabaJ
- Member
- 2045 posts
- Joined: Sept. 2015
- Offline
If it's just the two primitives, you can run it over primitives with:
int Count, Count_A;
int S[], T[];
S = i[]@Test;
T = prim(geoself(), "Test", 1);
if(@primnum == 0)
{
for(Count = 0; Count < len(S); Count++)
{
for(Count_A = 0; Count_A < len(T); Count_A++)
{
if( T[Count] == S[Count_A] )
{
i@group_Common = 1;
setprimgroup(geoself(), "Common", 1, 1, "set");
}
}
}
}
- olivierth
- Member
- 1012 posts
- Joined: April 2017
- Offline
- Andr
- Member
- 900 posts
- Joined: Feb. 2016
- Offline
Python has a built-in function intersection that works with sets (have a look at method2)
https://www.geeksforgeeks.org/python-intersection-two-lists/ [www.geeksforgeeks.org]
https://www.geeksforgeeks.org/python-intersection-two-lists/ [www.geeksforgeeks.org]
- olivierth
- Member
- 1012 posts
- Joined: April 2017
- Offline
-
- Quick Links