I can convert getPos() to numpy array quick using the buffer by:

np.array([*self._pdnp.getPos()], copy=False)

But I cannot do this using Matrix3f since it is not flat. Is there an elegant way to do this? I do not want to access specific elements.

I can convert getPos() to numpy array quick using the buffer by:

np.array([*self._pdnp.getPos()], copy=False)

But I cannot do this using Matrix3f since it is not flat. Is there an elegant way to do this? I do not want to access specific elements.

It’s simple.

```
from panda3d.core import LMatrix3f
import numpy as np
mat = LMatrix3f(19, 23, 9, 2, 9, 12, 39, 3, 3)
np_mat = np.array(mat)
print(np_mat)
```

1 Like

By the way, I would like to ask more questions related to this topic:

I have a rotation matrix in numpy (3,3), and want to assign it to a nodepath.

There seems to be no functions like setMat3. Should I convert it to Quat first?

Also, is there a simple way to convert numpy back to Matrix3f?

I tried LMatrix3f(Numpy), it did not work. the best solution I have right now is *numpy.flatten(), which, I think, is a bit ugly.

I’m not sure if it’s elegant, but as an option. By the way, the code doesn’t have to be elegant - it has to work.

```
from panda3d.core import LMatrix3f, NodePath
import numpy as np
mat = LMatrix3f(19, 23, 9, 2, 9, 12, 39, 3, 3)
node_path = NodePath("empty")
node_path.set_mat(mat)
np_mat = np.array(mat)
node_path.set_mat(LMatrix3f(*np_mat[0], *np_mat[1], *np_mat[2]))
```

2 Likes

Thanks! I guess I will follow your suggestion then.