pyvista.core._validation.validate.validate_arrayN_unsigned

pyvista.core._validation.validate.validate_arrayN_unsigned#

validate_arrayN_unsigned(arr, /, *, reshape=True, **kwargs)[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:
arrarray_like[float, …] | array_like[int, …]

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_arrayN

Similar function for numeric one-dimensional arrays.

validate_array

Generic 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])