2

This is my first post so let me know if I need to change anything!

I've created a grid based on the following input:

1;2;12;12;12  
11;12;2;12;12  
1;2;12;2;12  
11;12;2;1;2  

To create this grid I used this piece of code:

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

text = node.evalParm('text')  
lines = text.splitlines()  
numbers = [map(int, line.split(';') ) for line in lines]  

geo.addAttrib(hou.attribType.Point, 'instance', -1)  

for row, n in enumerate(numbers):  
    for col, value in enumerate(n):  
    pos = (col, 0.0, row)  
    pt_add = geo.createPoint()  
    pt_add.setAttribValue('instance', value)  
    pt_add.setPosition(pos)   

This works great and creates the grid with points spaced 1 apart and with the correct value. Now I want to do the following:

if value != 0:
        a = #Value of current index
        b = #Value of index above
        if len(a) < len(b):
            if a[-len(a)] == b[-len(a)]:            
                a = '0'
                b = b
            else:
                pass
        else: 
            if len(a)== len(b):
                if len(a) < 2:
                    pass
                else:
                    a = '0'
                    b = b + 'x'
            else:
                if a[-len(a)] == b[-len(a)]: 
                    b = a + 'y'
                    a = '0'
                else:
                    pass 

Now I'm assuming I need to go over the rows and columns again but if I do that with a for loop then it won't allow me to call the value of the index above in that column. Could someone help me figure this out? And I'll need to change the value of "instance" to the new value.

As a brief explanation of what I'm trying to achieve: Example image

Edit: Adding something other than x or y to the int to differentiate between a "11" with 1 changed to "0" under it and an "11" with 2 or 3 changed to "0" under them.

  • You might be interested in researching the numpy package for matrix operations and arithmetic. – crowgers Jan 14 '19 at 11:20
  • numpy was for comparing matrixes to each other no? So would we then make a copy of our matrix to compare it to the original matrix? - This will need to work with matrixes of around 1000x1000 so manual input is not going to work. – Thomas van Fucht Jan 14 '19 at 11:27
  • Exactly, you could take the hadamard product in this case. If your problem is more complicated then this, can you provide more information on the problem space you are working with ? – crowgers Jan 14 '19 at 13:24
  • I'm honesty unfamiliar with numpy and comparing matrixes, so i'm not entirely sure how I would start – Thomas van Fucht Jan 14 '19 at 14:03
  • Ok, well it might be useful to more rigorously define the problem space, i.e. Where are the matrices coming from? Is the change to the matrices consistent or will it be different every time? if it's different how are you modelling this? How constrained by memory are you? how constrained by time are you? in your above picture example it looks like you need the hadamard product of input with (`1;1;1;'x';'y'` `1;1;0;0;0` `0;0;1;0;0` `1;11;0;1;0`) In most cases numpy has excellent tools for manipulating matrices: https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.array.html – crowgers Jan 14 '19 at 15:40
  • You can also create matrices from input csv's using numpy: https://stackoverflow.com/questions/4315506/load-csv-into-2d-matrix-with-numpy-for-plotting – crowgers Jan 14 '19 at 15:46
  • ok so the matrixes are coming from a csv file of which the first 5 lines are to be disregarded. However all the columns in the csv are condensed into the first column, so it's filled with number;number;number ect. This has to work for any variant of input. I have quite a lot of memory so we should be ok, same for time unless it's ridiculous. – Thomas van Fucht Jan 15 '19 at 09:17

0 Answers0