testing.
assert_array_less
如果两个类似数组的对象的顺序不是小于,则引发断言错误。
对于两个类似数组的对象,检查形状是否相等,并且第一个对象的所有元素都严格小于第二个对象的元素。在形状不匹配或顺序不正确的值处引发异常。如果对象的维度为零,则形状不匹配不会引发。与numpy中的标准用法不同,对nan进行比较,如果两个对象在相同位置上都有nan,则不会引发断言。
要检查的较小对象。
要比较的较大对象。
出现故障时要打印的错误消息。
如果为true,则将冲突值追加到错误消息中。
如果实际对象和所需对象不相等。
参见
assert_array_equal
测试对象是否相等
assert_array_almost_equal
等精度试验对象
实例
>>> np.testing.assert_array_less([1.0, 1.0, np.nan], [1.1, 2.0, np.nan]) >>> np.testing.assert_array_less([1.0, 1.0, np.nan], [1, 2.0, np.nan]) Traceback (most recent call last): ... AssertionError: Arrays are not less-ordered Mismatched elements: 1 / 3 (33.3%) Max absolute difference: 1. Max relative difference: 0.5 x: array([ 1., 1., nan]) y: array([ 1., 2., nan])
>>> np.testing.assert_array_less([1.0, 4.0], 3) Traceback (most recent call last): ... AssertionError: Arrays are not less-ordered Mismatched elements: 1 / 2 (50%) Max absolute difference: 2. Max relative difference: 0.66666667 x: array([1., 4.]) y: array(3)
>>> np.testing.assert_array_less([1.0, 2.0, 3.0], [4]) Traceback (most recent call last): ... AssertionError: Arrays are not less-ordered (shapes (3,), (1,) mismatch) x: array([1., 2., 3.]) y: array([4])