get_array

PolyData.get_array(name: str, preference: Literal[cell, point, field] = 'cell') numpy.ndarray

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

Parameters
namestr

Name of the array.

preferencestr, optional

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
>>> mesh = pyvista.Cube().clean()
>>> 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')
array([0, 1, 2, 3, 4, 5, 6, 7])

Get the cell data array.

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

Get the field data array.

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