pyvista_validation.check.check_shape#
- pyvista_validation.check.check_shape(array: _ArrayLikeOrScalar[NumberType], /, shape: _ShapeLike | list[_ShapeLike], *, name: str = 'Array') None#
Check if an array has the specified shape.
- Parameters:
- arrayfloat | ArrayLike[float]
Number or array to check.
- shapeShapeLike | list[ShapeLike]
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 (that is, 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 shapes.
See also
Examples
Check if an array is one-dimensional.
>>> import numpy as np >>> from pyvista_validation import check_shape >>> check_shape([1, 2, 3], shape=(-1))
Check if an array is one-dimensional or a scalar.
>>> check_shape(1, shape=[(), (-1)])
Check if an array is 3x3 or 4x4.
>>> check_shape(np.eye(3), shape=[(3, 3), (4, 4)])