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!

Link to comment
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
Link to comment
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
Link to comment
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. 

Link to comment
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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...