alr77 Posted February 1, 2018 Share Posted February 1, 2018 Dear all, Sorry if my question looks naive, as you're all surely usual with this : matrix reading /printing. But i'd like to "printf" it element by element. Usually, generally a matrix looks like : matrix M[r][c] -> then your iter through. eg : print(M[1][1]+"\n"); But here in Hou it is : matrix M Yes printf() prints the thing but the whole thing. Then, how to read elements one by one separatly, please? i humbly dunno. Am usual with this practice in other languages because Matrices could be used as a fantastic "Chest" to store values, compiling vectors pack, and on and on... So any advices to this practical question are welcome. Thank you a lot. Bests, Quote Link to comment Share on other sites More sharing options...
f1480187 Posted February 2, 2018 Share Posted February 2, 2018 For some reason M[1][1] is not working in VEX, but you can always use getcomp(M, 1, 1). for (int row = 0; row < 4; row++) { string out = ""; for (int col = 0; col < 4; col++) { float value = getcomp(4@test, row, col); out += sprintf("%g ", value); } printf(out + "\n"); } Matrices in Houdini are not m×n arrays, but 4-, 9- and 16-float "vectors". They rarely used as storage, as there is one-dimension arrays available for this purpose. Python is generally used for more sophisticated arrays manipulation. NumPy available by default. import numpy node = hou.pwd() geo = node.geometry() mat = geo.floatListAttribValue('test'); val = numpy.array(mat).reshape((4, 4)) print(val) print_matrix.hipnc 1 Quote Link to comment Share on other sites More sharing options...
alr77 Posted February 2, 2018 Author Share Posted February 2, 2018 Dear F1, Thank you for explanations, because i've found myself in front of a locked door which finally was more like an illusion as you're explaining the classic "for" iteration is working. Thus we can say even if the academic notation : M[][] doesn't work, its functionality is implicitly embeded inside DOGMATIC 2x2 3x3 or 4x4...so...perfect. i deduce then the reverse getcomp() is setcomp(). I can now, sort, store , arrage datas inside. GR8 ! Thank you twice F1, and enjoy the week end. bests, alr + + + 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.