# vex - arrays

## Recommended Posts

Hi Guys,
I am wondering if there is any way in vex to compare between two arrays to get the difference.
Please let me know is there any way to do this,

below is what I am trying to do

```s[]@attribsA = detailintrinsic(0, "pointattributes");
s[]@attribsB = detailintrinsic(1, "pointattributes");
s[]@AB = @attribsA - @attribsB; //need mismatched attributes in a
s[]@BA = @attribsB - @attribsA; //need mismatched attributes in b```

##### Share on other sites

I don't think so, but it's relatively straight forward exploiting the sort functions

```i[]@arr1 = {0, 30, 1, 47, 48};
i[]@arr2 = {0, 41, 48, 1341, 1};

function int[] sorted(int arr1[]; int arr2[]) {
int _arr1[] = sort(arr1);
int _arr2[] = sort(arr2);
int result[];
foreach(int i; _arr1) {
foreach(int j; _arr2) {
if (i == j) push(result, i);
}
}
return result;
}

i[]@arr_sorted = sorted(i[]@arr1, i[]@arr2); ```

• 3

##### Share on other sites

Numpy also seems to be suitable for comparing arrays, e.g. setdiff1d() for extracting "left-overs".

```import numpy

node = hou.pwd()
geo = node.geometry()

arr1 = geo.intListAttribValue('arr1')
arr2 = geo.intListAttribValue('arr2')

AB = numpy.setdiff1d(arr1, arr2)
BA = numpy.setdiff1d(arr2, arr1)

I just dont know how to create proper array attributes with Python. Currently it returns just a bunch of integer attributes

• 1

##### Share on other sites
On 20/12/2018 at 7:59 PM, vtrvtr said:

I don't think so, but it's relatively straight forward exploiting the sort functions

```
i[]@arr1 = {0, 30, 1, 47, 48};
i[]@arr2 = {0, 41, 48, 1341, 1};

function int[] sorted(int arr1[]; int arr2[]) {
int _arr1[] = sort(arr1);
int _arr2[] = sort(arr2);
int result[];
foreach(int i; _arr1) {
foreach(int j; _arr2) {
if (i == j) push(result, i);
}
}
return result;
}

i[]@arr_sorted = sorted(i[]@arr1, i[]@arr2); ```

Thank you very much vtrvtr. I think should be enough for my purposes.

##### Share on other sites
On 21/12/2018 at 1:28 AM, konstantin magnus said:

Numpy also seems to be suitable for comparing arrays, e.g. setdiff1d() for extracting "left-overs".

```
import numpy

node = hou.pwd()
geo = node.geometry()

arr1 = geo.intListAttribValue('arr1')
arr2 = geo.intListAttribValue('arr2')

AB = numpy.setdiff1d(arr1, arr2)
BA = numpy.setdiff1d(arr2, arr1)

I just dont know how to create proper array attributes with Python. Currently it returns just a bunch of integer attributes

Hi konstatin magnus,i never thought of numpy, Ill give a try in python thanks for the idea. Thanks for the help

## Create an account

Register a new account

×
• Donations