DataSetAttributes.set_array(data: Union[Sequence[Union[float, int]], float, int, numpy.ndarray], name: str, deep_copy=False) None[source]#

Add an array to this object.

Use this method when adding arrays to the DataSet. If needed, these arrays can later be assigned to become the active scalars, vectors, normals, or texture coordinates with:


A pyvista_ndarray, numpy.ndarray, list, tuple or scalar value.


Name to assign to the data. If this name already exists, it will be overwritten.

deep_copybool, optional

When True makes a full copy of the array.


You can simply use the [] operator to add an array to the dataset. Note that this will automatically become the active scalars.


Add a point array to a mesh.

>>> import pyvista
>>> mesh = pyvista.Cube()
>>> data = range(mesh.n_points)
>>> mesh.point_data.set_array(data, 'my-data')
>>> mesh.point_data['my-data']
pyvista_ndarray([0, 1, 2, 3, 4, 5, 6, 7])

Add a cell array to a mesh.

>>> cell_data = range(mesh.n_cells)
>>> mesh.cell_data.set_array(cell_data, 'my-data')
>>> mesh.cell_data['my-data']
pyvista_ndarray([0, 1, 2, 3, 4, 5])

Add field data to a mesh.

>>> field_data = range(3)
>>> mesh.field_data.set_array(field_data, 'my-data')
>>> mesh.field_data['my-data']
pyvista_ndarray([0, 1, 2])