bundles / numpy latest / numpy / testing / _private / utils / assert_array_less
function
numpy.testing._private.utils:assert_array_less
source: build-install/usr/lib/python3.14/site-packages/numpy/testing/_private/utils.py :1228
Signature
def assert_array_less ( x , y , err_msg = '' , verbose = True , * , strict = False ) Summary
Raises an AssertionError if two array_like objects are not ordered by less than.
Extended Summary
Given two array_like objects x and y, check that the shape is equal and all elements of x are strictly less than the corresponding elements of y (but see the Notes for the special handling of a scalar). An exception is raised at shape mismatch or values that are not correctly ordered. In contrast to the standard usage in NumPy, no assertion is raised if both objects have NaNs in the same positions.
Parameters
x: array_likeThe smaller object to check.
y: array_likeThe larger object to compare.
err_msg: stringThe error message to be printed in case of failure.
verbose: boolIf True, the conflicting values are appended to the error message.
strict: bool, optionalIf True, raise an AssertionError when either the shape or the data type of the array_like objects does not match. The special handling for scalars mentioned in the Notes section is disabled.
Raises
: AssertionErrorIf x is not strictly smaller than y, element-wise.
Notes
When one of x and y is a scalar and the other is array_like, the function performs the comparison as though the scalar were broadcasted to the shape of the array. This behaviour can be disabled with the strict parameter.
Examples
The following assertion passes because each finite element of `x` is strictly less than the corresponding element of `y`, and the NaNs are in corresponding locations.x = [1.0, 1.0, np.nan] y = [1.1, 2.0, np.nan] np.testing.assert_array_less(x, y)The following assertion fails because the zeroth element of `x` is no longer strictly less than the zeroth element of `y`.
y[0] = 1 np.testing.assert_array_less(x, y)Here, `y` is a scalar, so each element of `x` is compared to `y`, and the assertion passes.
x = [1.0, 4.0] y = 5.0 np.testing.assert_array_less(x, y)However, with ``strict=True``, the assertion will fail because the shapes do not match.
np.testing.assert_array_less(x, y, strict=True)
With ``strict=True``, the assertion also fails if the dtypes of the two
arrays do not match.
y = [5, 5] np.testing.assert_array_less(x, y, strict=True)
See also
- assert_array_almost_equal
test objects for equality up to precision
- assert_array_equal
tests objects for equality
Aliases
-
numpy.testing.assert_array_less