DataSetAttributes.set_array#
- DataSetAttributes.set_array( ) 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:
Deprecated since version 0.50: Setting a scalar is deprecated. Broadcast the value with
numpy.full()to set point or cell data, or useuser_dictto store scalar metadata.- Parameters:
- data
numpy.ndarray| sequence Array of data.
- name
str Name to assign to the data. If this name already exists, it will be overwritten.
- deep_copybool, optional
When
Truemakes a full copy of the array.
- data
Notes#
You can simply use the [] operator to add an array to the
dataset. Note that this will automatically become the active
scalars.
Examples#
Download Python source code | Download Jupyter notebook
Add a point array to a mesh.
>>> import pyvista as pv
>>> mesh = pv.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])