I tend to write too many things on the same line in Python and this caused an unexpected behavior for the numpy vnl bridge. It occurred in a different context but I have the following minimal example
import itk m = itk.Matrix[itk.D,4,4]() m.SetIdentity() m2 = m+m print(itk.GetArrayFromVnlMatrix((m+m).GetVnlMatrix().as_matrix())) print(itk.GetArrayFromVnlMatrix(m2.GetVnlMatrix().as_matrix()))
which should show the same two matrices but actually shows
[[4.68850067e-310 0.00000000e+000 0.00000000e+000 0.00000000e+000] [0.00000000e+000 2.00000000e+000 0.00000000e+000 0.00000000e+000] [0.00000000e+000 0.00000000e+000 2.00000000e+000 0.00000000e+000] [0.00000000e+000 0.00000000e+000 0.00000000e+000 2.00000000e+000]] [[2. 0. 0. 0.] [0. 2. 0. 0.] [0. 0. 2. 0.] [0. 0. 0. 2.]]
Any clue what’s going on and if this can and should be corrected? It seems to be some memory release before the deep copy of the numpy array but I could not see what was wrong in the bridge code.
Thanks in advance!