pyvista.UnstructuredGrid.cells#

property UnstructuredGrid.cells: ndarray[source]#

Return the cell data as a numpy object.

This is the old style VTK data layout:

[n0, p0_0, p0_1, ..., p0_n, n1, p1_0, p1_1, ..., p1_n, ...]

where n0 is the number of points in cell 0, and pX_Y is the Y’th point in cell X.

For example, a triangle and a line might be represented as:

[3, 0, 1, 2, 2, 0, 1]

Where the two individual cells would be [3, 0, 1, 2] and [2, 0, 1].

Notes

The array returned cannot be modified in place and will raise a ValueError if attempted.

You can, however, set the cells directly. See the example.

Examples

Return the indices of the first two cells from the example hex beam. Note how the cells have “padding” indicating the number of points per cell.

>>> import pyvista as pv
>>> from pyvista import examples
>>> grid = examples.load_hexbeam()
>>> grid.cells[:18]
array([ 8,  0,  2,  8,  7, 27, 36, 90, 81,  8,  2,  1,  4,  8, 36, 18, 54,
       90])

While you cannot change the array inplace, you can overwrite it. For example:

>>> grid.cells = [8, 0, 1, 2, 3, 4, 5, 6, 7]