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,可选
相对容差.相对差等于
rtol * b. 默认值为 1e-5.- atolfloat,可选
绝对容差.绝对差等于 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