MCPcopy Create free account
hub / github.com/numpy/numpy / assert_array_less

Function assert_array_less

numpy/testing/_private/utils.py:1039–1115  ·  view source on GitHub ↗

Raises an AssertionError if two array_like objects are not ordered by less than. Given two array_like objects, check that the shape is equal and all elements of the first object are strictly smaller than those of the second object. An exception is raised at shape mismatch or in

(x, y, err_msg='', verbose=True)

Source from the content-addressed store, hash-verified

1037
1038
1039def assert_array_less(x, y, err_msg='', verbose=True):
1040 """
1041 Raises an AssertionError if two array_like objects are not ordered by less
1042 than.
1043
1044 Given two array_like objects, check that the shape is equal and all
1045 elements of the first object are strictly smaller than those of the
1046 second object. An exception is raised at shape mismatch or incorrectly
1047 ordered values. Shape mismatch does not raise if an object has zero
1048 dimension. In contrast to the standard usage in numpy, NaNs are
1049 compared, no assertion is raised if both objects have NaNs in the same
1050 positions.
1051
1052 Parameters
1053 ----------
1054 x : array_like
1055 The smaller object to check.
1056 y : array_like
1057 The larger object to compare.
1058 err_msg : string
1059 The error message to be printed in case of failure.
1060 verbose : bool
1061 If True, the conflicting values are appended to the error message.
1062
1063 Raises
1064 ------
1065 AssertionError
1066 If x is not strictly smaller than y, element-wise.
1067
1068 See Also
1069 --------
1070 assert_array_equal: tests objects for equality
1071 assert_array_almost_equal: test objects for equality up to precision
1072
1073 Examples
1074 --------
1075 >>> np.testing.assert_array_less([1.0, 1.0, np.nan], [1.1, 2.0, np.nan])
1076 >>> np.testing.assert_array_less([1.0, 1.0, np.nan], [1, 2.0, np.nan])
1077 Traceback (most recent call last):
1078 ...
1079 AssertionError:
1080 Arrays are not less-ordered
1081 <BLANKLINE>
1082 Mismatched elements: 1 / 3 (33.3%)
1083 Max absolute difference: 1.
1084 Max relative difference: 0.5
1085 x: array([ 1., 1., nan])
1086 y: array([ 1., 2., nan])
1087
1088 >>> np.testing.assert_array_less([1.0, 4.0], 3)
1089 Traceback (most recent call last):
1090 ...
1091 AssertionError:
1092 Arrays are not less-ordered
1093 <BLANKLINE>
1094 Mismatched elements: 1 / 2 (50%)
1095 Max absolute difference: 2.
1096 Max relative difference: 0.66666667

Callers 4

test_partitionMethod · 0.90
assert_partitionedMethod · 0.90
test_svd_no_uvMethod · 0.90

Calls 1

assert_array_compareFunction · 0.70

Tested by 4

test_partitionMethod · 0.72
assert_partitionedMethod · 0.72
test_svd_no_uvMethod · 0.72