pyvista.DataSet.get_array

pyvista.DataSet.get_array#

DataSet.get_array(
name: str,
preference: Literal['cell', 'point', 'field'] = 'cell',
) pyvista.pyvista_ndarray[source]#

Search both point, cell and field data for an array.

Parameters:
namestr

Name of the array.

preferencestr, default: “cell”

When scalars is specified, this is the preferred array type to search for in the dataset. Must be either 'point', 'cell', or 'field'.

Returns:
pyvista.pyvista_ndarray

Requested array.

Examples

Create a DataSet with a variety of arrays.

>>> import pyvista as pv
>>> mesh = pv.Cube()
>>> mesh.clear_data()
>>> mesh.point_data['point-data'] = range(mesh.n_points)
>>> mesh.cell_data['cell-data'] = range(mesh.n_cells)
>>> mesh.field_data['field-data'] = ['a', 'b', 'c']
>>> mesh.array_names
['point-data', 'field-data', 'cell-data']

Get the point data array.

>>> mesh.get_array('point-data')
pyvista_ndarray([0, 1, 2, 3, 4, 5, 6, 7])

Get the cell data array.

>>> mesh.get_array('cell-data')
pyvista_ndarray([0, 1, 2, 3, 4, 5])

Get the field data array.

>>> mesh.get_array('field-data')
pyvista_ndarray(['a', 'b', 'c'], dtype='<U1')