# matlab martix to vtkMatrix4x4

**URL:** https://discourse.vtk.org/t/matlab-martix-to-vtkmatrix4x4/1419
**Category:** Development
**Created:** [July 25, 2019, 3:06pm UTC](https://discourse.vtk.org/t/matlab-martix-to-vtkmatrix4x4/1419 "2019-07-25T15:06:07Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [July 25, 2019, 5:24pm UTC](https://discourse.vtk.org/t/matlab-martix-to-vtkmatrix4x4/1419/3 "2019-07-25T17:24:31Z")

</div>

Conversion is possible with the DeepCopy() methods that were originally written to be used with C arrays. The ndarray.ravel() method returns a flattened view of the numpy array that can be used with DeepCopy:

```
import numpy as np
import vtk

m = vtk.vtkMatrix4x4()
# make some numpy arrays
a = np.random.rand(4,4)
b = np.zeros((4,4))
# copy from numpy to vtkMatrix4x4
m.DeepCopy(a.ravel())
# copy from vtkMatrix4x4 to numpy
m.DeepCopy(b.ravel(), m)
print(a)
print(b)
print(m)

```

This uses the Python sequence protocol rather than the Python buffer protocol. For a 16-element matrix, however, there can’t be a significant performance difference.

I don’t really do maintenance of the VTK numpy support code. But if somebody submits a patch, I’d be happy to review it.

---

_[View the full topic](https://discourse.vtk.org/t/matlab-martix-to-vtkmatrix4x4/1419)._
