pyvista_validation.validate.validate_arrayN_unsigned#
- pyvista_validation.validate.validate_arrayN_unsigned(arr: VectorLike[float], /, *, reshape: bool = True, **kwargs) NumpyArray[int]#
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:
- arrVectorLike[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.- **kwargsdict, optional
Additional keyword arguments passed to
validate_array().
- Returns:
- np.ndarray
Validated 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_validation import validate_arrayN_unsigned >>> arr = 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.
>>> validate_arrayN_unsigned(42) array([42])
2D arrays where the first dimension is unity are automatically reshaped to be 1D.
>>> validate_arrayN_unsigned([[1, 2]]) array([1, 2])
Add additional constraints if needed.
>>> validate_arrayN_unsigned((1, 2, 3), must_be_in_range=[1, 3]) array([1, 2, 3])