pyvista_ndarray.squeeze

Contents

pyvista_ndarray.squeeze#

pyvista_ndarray.squeeze(
axis: SupportsIndex | tuple[SupportsIndex, ...] | None = None,
) Self#

Remove axes of length one while retaining an array view.

Changed in version 0.50: Single-element inputs return zero-dimensional array views.

Parameters:
axisint or tuple[int, …], optional

Axes to remove. By default, remove all axes of length one. Selecting an axis of length greater than one raises a ValueError.

Returns:
pyvista.pyvista_ndarray

View of the array with the selected axes removed. If all axes are removed, the result is a zero-dimensional array, not a scalar. If the shape is unchanged, return this array.

Examples#

Download Python source code | Download Jupyter notebook

>>> import pyvista as pv
>>> array = pv.pyvista_ndarray([[1]])
>>> squeezed = array.squeeze()
>>> squeezed.shape
()
>>> squeezed[...] = 2
>>> array
pyvista_ndarray([[2]])