Mohanpugaz Posted December 20, 2018 Share Posted December 20, 2018 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! Quote Link to comment Share on other sites More sharing options...
vtrvtr Posted December 20, 2018 Share Posted December 20, 2018 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 Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted December 20, 2018 Share Posted December 20, 2018 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 1 Quote Link to comment Share on other sites More sharing options...
Mohanpugaz Posted December 25, 2018 Author Share Posted December 25, 2018 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. Quote Link to comment Share on other sites More sharing options...
Mohanpugaz Posted December 25, 2018 Author Share Posted December 25, 2018 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 Hi konstatin magnus,i never thought of numpy, Ill give a try in python thanks for the idea. Thanks for the help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.