numpy.testing.assert_array_max_ulp#
- testing.assert_array_max_ulp(a, b, maxulp=1, dtype=None)[源码]#
检查数组中的所有项最多相差 N 个最后位单位。
- 参数:
- a, barray_like
要比较的输入数组。
- maxulpint, optional
元素 a 和 b 之间在最后一位(last place)上允许的最大差值。默认是 1。
- dtypedtype, optional
如果给定,则将 a 和 b 转换为的数据类型。默认是 None。
- 返回:
- retndarray
包含 a 和 b 之间的可表示浮点数数量的数组。
- 引发:
- AssertionError
如果一个或多个元素相差超过 maxulp。
另请参阅
assert_array_almost_equal_nulp相对于它们的间距比较两个数组。
备注
对于 ULP 差值的计算,此 API 不区分 NAN 的各种表示形式(0x7fc00000 和 0xffc00000 之间的 ULP 差值为零)。
示例
>>> a = np.linspace(0., 1., 100) >>> res = np.testing.assert_array_max_ulp(a, np.arcsin(np.sin(a)))