Jump to content

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


Thanks a lot in advance!

Share this post


Link to post
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); 

 

  • Like 3

Share this post


Link to post
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)

geo.addAttrib(hou.attribType.Global, 'arr_AB', AB, create_local_variable=False)
geo.addAttrib(hou.attribType.Global, 'arr_BA', BA, create_local_variable=False)

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

  • Like 1

Share this post


Link to post
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 this post


Link to post
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)

geo.addAttrib(hou.attribType.Global, 'arr_AB', AB, create_local_variable=False)
geo.addAttrib(hou.attribType.Global, 'arr_BA', BA, create_local_variable=False)

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

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×