Time for action – checking the array order
Let's check whether one array is strictly greater than another array:
- Call the
assert_array_less()
function with two strictly ordered arrays:print("Pass", np.testing.assert_array_less([0, 0.123456789, np.nan], [1, 0.23456780, np.nan]))
The result is as follows:
Pass None
- Call the
assert_array_less()
function:print("Fail", np.testing.assert_array_less([0, 0.123456789, np.nan], [0, 0.123456780, np.nan]))
The test raises an exception:
Fail Traceback (most recent call last): ... raise AssertionError(msg) AssertionError: Arrays are not less-ordered (mismatch 100.0%) x: array([ 0. , 0.12345679, nan]) y: array([ 0. , 0.12345678, nan])
What just happened?
We checked the ordering of two arrays with the assert_array_less()
function.