pyvista.core._validation.validate.validate_arrayN_unsigned#
- validate_arrayN_unsigned( ) NumpyArray[int][source]#
Validate a numeric 1D array of non-negative (unsigned) integers.
The array is checked to ensure its input values:
have shape
(N,)or can be reshaped to(N,)are integer-like
are non-negative
The returned array is formatted so that its values:
have shape
(N,)have an integer data type
- Parameters:
- arr
VectorLike[float] Array to validate.
- reshapebool, default:
True If
True, 0-dimensional scalars are reshaped to(1,)and 2D vectors with shape(1, N)are reshaped to(N,)to ensure the output is consistently one-dimensional. Otherwise, all scalar and 2D inputs are not considered valid.- **kwargs
dict,optional Additional keyword arguments passed to
validate_array().
- arr
- Returns:
np.ndarrayValidated 1D array with non-negative integers.
See also
validate_arrayNSimilar function for numeric one-dimensional arrays.
validate_arrayGeneric array validation function.
Examples
Validate a 1D array with four non-negative integer-like elements.
>>> import numpy as np >>> from pyvista import _validation >>> arr = _validation.validate_arrayN_unsigned((1.0, 2.0, 3.0, 4.0)) >>> arr array([1, 2, 3, 4])
Verify that the output data type is integral.
>>> np.issubdtype(arr.dtype, int) True
Scalar 0-dimensional values are automatically reshaped to be 1D.
>>> _validation.validate_arrayN_unsigned(42) array([42])
2D arrays where the first dimension is unity are automatically reshaped to be 1D.
>>> _validation.validate_arrayN_unsigned([[1, 2]]) array([1, 2])
Add additional constraints if needed.
>>> _validation.validate_arrayN_unsigned((1, 2, 3), must_be_in_range=[1, 3]) array([1, 2, 3])