validate_numeric_array#

validate_numeric_array(arr, name, *, shape=None, size=None)[source]#

Validate that arr is a numeric NumPy array of the expected extent.

A numeric dtype is any integer, unsigned-integer, floating, or complex dtype; real arrays are accepted where a complex field is expected because they are a valid special case.

Parameters:
  • arr (object) – The value to validate.

  • name (str) – Name of the argument, used in error messages.

  • shape (tuple of int, optional) – If given, the exact shape arr must have.

  • size (int, optional) – If given, the exact number of elements arr must have.

Returns:

The validated arr (returned unchanged for convenient chaining).

Return type:

numpy.ndarray

Raises:
  • TypeError – If arr is not a numpy.ndarray.

  • ValueError – If arr is not numeric or does not match shape/size.