pyvista_validation.validate.validate_array3#
- pyvista_validation.validate.validate_array3(arr, *, reshape=True, broadcast=False, **kwargs)#
Validate a numeric 1D array with 3 elements.
The array is checked to ensure its input values:
have shape
(3,)or can be reshaped to(3,)are numeric and real
The returned array is formatted so that it has shape
(3,).- Parameters:
- arrfloat | VectorLikeFloat | MatrixLikeFloat
Array to validate.
- reshapebool, default: True
If
True, 2D vectors with shape(1, 3)are considered valid input, and are reshaped to(3,)to ensure the output is consistently one-dimensional.- broadcastbool, default: False
If
True, scalar values or 1D arrays with a single element are considered valid input and the single value is broadcast to a length 3 array.- **kwargsdict, optional
Additional keyword arguments passed to
validate_array().
- Returns:
- np.ndarray
Validated 1D array with 3 elements.
See also
validate_numberSimilar function for a single number.
validate_arrayNSimilar function for one-dimensional arrays.
validate_arrayGeneric array validation function.
Examples
Validate a 1D array with three elements.
>>> from pyvista_validation import validate_array3 >>> validate_array3((1, 2, 3)) array([1, 2, 3])
2D 3-element arrays are automatically reshaped to be 1D.
>>> validate_array3([[1, 2, 3]]) array([1, 2, 3])
Scalar 0-dimensional values can be automatically broadcast as a 3-element 1D array.
>>> validate_array3(42.0, broadcast=True) array([42., 42., 42.])
Add additional constraints if needed.
>>> validate_array3((1, 2, 3), must_be_nonnegative=True) array([1, 2, 3])