pyvista.core._validation.check.check_shape#

check_shape(arr, /, shape, *, name='Array')[source]#

Check if an array has the specified shape.

Parameters:
arrarray_like

Array to check.

shapeint, tuple[int, …] | list[int, tuple[int, …]], optional

A single shape or a list of any allowable shapes. If an integer, i, the shape is interpreted as (i,). Use a value of -1 for any dimension where its size is allowed to vary, e.g. (-1,3) if any Nx3 array is allowed. Use () for the shape of scalar values (i.e. 0-dimensional). If a list, the array must have at least one of the specified shapes.

namestr, default: “Array”

Variable name to use in the error messages if any are raised.

Raises:
ValueError

If the array does not have any of the specified shape(s).

See also

check_length

Examples

Check if an array is one-dimensional.

>>> import numpy as np
>>> from pyvista import _validation
>>> _validation.check_shape([1, 2, 3], shape=(-1))

Check if an array is one-dimensional or a scalar.

>>> _validation.check_shape(1, shape=[(), (-1)])

Check if an array is 3x3 or 4x4.

>>> _validation.check_shape(np.eye(3), shape=[(3, 3), (4, 4)])