# Python: read unstructured to Numpy array

**URL:** <https://discourse.vtk.org/t/python-read-unstructured-to-numpy-array/12564>\
**Category:** Development\
**Created:** [October 29, 2023, 3:22pm UTC](https://discourse.vtk.org/t/python-read-unstructured-to-numpy-array/12564 "2023-10-29T15:22:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![scivision](https://discourse.vtk.org/user_avatar/discourse.vtk.org/scivision/32/7897_2.png) [@scivision](https://discourse.vtk.org/u/scivision)\
**Post date:** [October 29, 2023, 3:22pm UTC](https://discourse.vtk.org/t/python-read-unstructured-to-numpy-array/12564/1 "2023-10-29T15:22:01Z")

</div>

I can read a .vtu file and get the nodes and data. I would like to add a filter CellCenters so I get the parametric cell centers. I need to setup a filter to do this, but I’m new to VTK in Python and unfamiliar with the correct syntax. Here’s what I have that works to read the VTU files:

```python
def read_vtu(file):
    reader = vtk.vtkXMLUnstructuredGridReader()
    reader.SetFileName(file)
    reader.Update()

    output = reader.GetOutput()

    # coordinates of nodes in the mesh
    nodes_vtk = output.GetPoints().GetData()
    nodes = vtk_to_numpy(nodes_vtk)

    data = vtk_to_numpy(output.GetCellData().GetArray("MyVar"))

    return data, nodes

```
