ma.
allclose
如果两个数组在一个公差内按元素方向相等,则返回true。
此函数等价于 allclose 除了屏蔽值被视为相等(默认)或不相等,这取决于 masked_equal 参数。
masked_equal
要比较的输入数组。
是否在中隐藏值 a 和 b 被视为相等(真)或不相等(假)。默认情况下,它们被认为是相等的。
相对公差。相对差等于 rtol * b . 默认值为1e-5。
rtol * b
绝对公差。绝对差等于 atol . 默认值为1e-8。
如果两个数组在给定的公差内相等,则返回“真”,否则返回“假”。如果任一数组包含NaN,则返回False。
参见
all
any
numpy.allclose
非屏蔽 allclose .
笔记
如果下面的公式是元素方向的真,那么 allclose 返回true::
absolute(`a` - `b`) <= (`atol` + `rtol` * absolute(`b`))
如果的所有元素 a 和 b 在给定的公差范围内是相等的。
实例
>>> 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