pyvista_validation.check.check_ndim#
- pyvista_validation.check.check_ndim(array, /, ndim, *, name='Array')#
Check if an array has the specified number of dimensions.
Note
Scalar values have a dimension of
0.- Parameters:
- arrayfloat | ArrayLikeFloat
Number or array to check.
- ndimint | Sequence[int], optional
A single dimension or a sequence of allowable dimensions. If an integer, the array must have this number of dimensions. If a sequence, the array must have at least one of the specified number of dimensions.
- namestr, default: “Array”
Variable name to use in the error messages if any are raised.
- Returns:
- array_like
The input, unchanged.
- Raises:
- ValueError
If the array does not have the required number of dimensions.
See also
Examples
Check if an array is one-dimensional
>>> import numpy as np >>> from pyvista_validation import check_ndim >>> check_ndim([1, 2, 3], ndim=1) [1, 2, 3]
Check if an array is two-dimensional or a scalar.
>>> check_ndim(1, ndim=(0, 2)) 1