numpy.testing.assert_array_almost_equal_nulp#

testing.assert_array_almost_equal_nulp(x, y, nulp=1)[源代码]#

相对其间距比较两个数组.

这是一种相对稳健的方法来比较两个幅度可变的数组.

参数:
x, yarray_like

输入数组.

nulpint, 可选

容差的最后一位单元的最大数量(见注释).默认值为1.

返回:
None
引发:
AssertionError

如果一个或多个元素中 xy 之间的间距大于 nulp.

参见

assert_array_max_ulp

检查数组的所有元素在最后一位上最多相差N个单位.

spacing

返回 x 与其最近的相邻数之间的距离.

备注

如果以下条件不满足,则会引发断言:

abs(x - y) <= nulp * spacing(maximum(abs(x), abs(y)))

示例

>>> x = np.array([1., 1e-10, 1e-20])
>>> eps = np.finfo(x.dtype).eps
>>> np.testing.assert_array_almost_equal_nulp(x, x*eps/2 + x)
>>> np.testing.assert_array_almost_equal_nulp(x, x*eps + x)
Traceback (most recent call last):
  ...
AssertionError: Arrays are not equal to 1 ULP (max is 2)