numpy.ma.allclose

ma.allclose(a, b, masked_equal=True, rtol=1e-05, atol=1e-08)[源代码]

如果两个数组在一个公差内按元素方向相等,则返回true。

此函数等价于 allclose 除了屏蔽值被视为相等(默认)或不相等,这取决于 masked_equal 参数。

参数
a, barray_like

要比较的输入数组。

masked_equal可选的布尔

是否在中隐藏值 ab 被视为相等(真)或不相等(假)。默认情况下,它们被认为是相等的。

rtol可选浮动

相对公差。相对差等于 rtol * b . 默认值为1e-5。

atol可选浮动

绝对公差。绝对差等于 atol . 默认值为1e-8。

返回
y布尔

如果两个数组在给定的公差内相等,则返回“真”,否则返回“假”。如果任一数组包含NaN,则返回False。

参见

all, any
numpy.allclose

非屏蔽 allclose .

笔记

如果下面的公式是元素方向的真,那么 allclose 返回true::

absolute(`a` - `b`) <= (`atol` + `rtol` * absolute(`b`))

如果的所有元素 ab 在给定的公差范围内是相等的。

实例

>>> a = np.ma.array([1e10, 1e-7, 42.0], mask=[0, 0, 1])
>>> a
masked_array(data=[10000000000.0, 1e-07, --],
             mask=[False, False,  True],
       fill_value=1e+20)
>>> b = np.ma.array([1e10, 1e-8, -42.0], mask=[0, 0, 1])
>>> np.ma.allclose(a, b)
False
>>> a = np.ma.array([1e10, 1e-8, 42.0], mask=[0, 0, 1])
>>> b = np.ma.array([1.00001e10, 1e-9, -42.0], mask=[0, 0, 1])
>>> np.ma.allclose(a, b)
True
>>> np.ma.allclose(a, b, masked_equal=False)
False

不直接比较屏蔽值。

>>> a = np.ma.array([1e10, 1e-8, 42.0], mask=[0, 0, 1])
>>> b = np.ma.array([1.00001e10, 1e-9, 42.0], mask=[0, 0, 1])
>>> np.ma.allclose(a, b)
True
>>> np.ma.allclose(a, b, masked_equal=False)
False