pyvista.core._validation.validate.validate_arrayN

pyvista.core._validation.validate.validate_arrayN#

validate_arrayN(arr: float | VectorLike[float], /, *, reshape: bool = True, **kwargs)[source]#

Validate a numeric 1D array.

The array is checked to ensure its input values:

  • have shape (N,) or can be reshaped to (N,)

  • are numeric

The returned array is formatted so that its values:

  • have shape (N,)

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.

See also

validate_arrayN_unsigned

Similar function for non-negative integer arrays.

validate_array

Generic array validation function.

Examples

Validate a 1D array with four elements.

>>> from pyvista import _validation
>>> _validation.validate_arrayN((1, 2, 3, 4))
array([1, 2, 3, 4])

Scalar 0-dimensional values are automatically reshaped to be 1D.

>>> _validation.validate_arrayN(42.0)
array([42.0])

2D arrays where the first dimension is unity are automatically reshaped to be 1D.

>>> _validation.validate_arrayN([[1, 2]])
array([1, 2])

Add additional constraints if needed.

>>> _validation.validate_arrayN((1, 2, 3), must_have_length=3)
array([1, 2, 3])