DataSetAttributes.get_array(key: Union[str, int]) Union[pyvista.core.pyvista_ndarray.pyvista_ndarray, vtkmodules.vtkCommonCore.vtkDataArray, vtkmodules.vtkCommonCore.vtkAbstractArray][source]#

Get an array in this object.

keystr, int

The name or index of the array to return. Arrays are ordered within VTK DataSetAttributes, and this feature is mirrored here.

pyvista.pyvista_ndarray or vtkDataArray

Returns a pyvista.pyvista_ndarray if the underlying array is either a vtk.vtkDataArray or vtk.vtkStringArray. Otherwise, returns a vtk.vtkAbstractArray.


If the key does not exist.


This is provided since arrays are ordered within VTK and can be indexed via an int. When getting an array, you can just use the key of the array with the [] operator with the name of the array.


Store data with point association in a DataSet.

>>> import pyvista
>>> mesh = pyvista.Cube()
>>> mesh.clear_data()
>>> mesh.point_data['my_data'] = range(mesh.n_points)

Access using an index.

>>> mesh.point_data.get_array(0)
pyvista_ndarray([0, 1, 2, 3, 4, 5, 6, 7])

Access using a key.

>>> mesh.point_data.get_array('my_data')
pyvista_ndarray([0, 1, 2, 3, 4, 5, 6, 7])