numpy.ma.allclose#
- ma.allclose(a, b, masked_equal=True, rtol=1e-05, atol=1e-08)[源代码]#
如果两个数组在容差范围内按元素方式相等,则返回 True.
此函数等效于
allclose,不同之处在于,根据masked_equal参数,屏蔽值被视为相等(默认)或不相等.- 参数:
- a, barray_like
要比较的输入数组.
- masked_equalbool,可选
a 和 b 中的屏蔽值是否被视为相等 (True) 或不相等 (False).默认情况下,它们被认为是相等的.
- rtolfloat, optional
相对容差.相对差等于
rtol * b.默认为 1e-5.- atolfloat, optional
绝对容差.绝对差等于 atol .默认为 1e-8.
- 返回:
- ybool
如果两个数组在给定的容差范围内相等,则返回 True,否则返回 False.如果任一数组包含 NaN,则返回 False.
参见
all,anynumpy.allclose非屏蔽的
allclose.
注释
如果以下等式是元素方向上的 True,则
allclose返回 True:absolute(`a` - `b`) <= (`atol` + `rtol` * absolute(`b`))
如果 a 和 b 的所有元素在给定的容差下都相等,则返回 True.
示例
>>> import numpy as np >>> 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