pyvista.DataSetAttributes.get_array#

DataSetAttributes.get_array(
key: str | int,
) pyvista_ndarray[source]#

Get an array in this object.

Parameters:
keystr | int

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

Returns:
pyvista.pyvista_ndarray

Returns a pyvista.pyvista_ndarray.

Raises:
KeyError

If the key does not exist.

Notes

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.

Examples

Store data with point association in a DataSet.

>>> import pyvista as pv
>>> mesh = pv.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])