How should you compare a near-zero reading to a reference?
isclose combines an absolute allowance with one relative to the reference magnitude. For a zero reference only the absolute allowance remains.
numpy.isclose in practice
With a tolerance of 0.001 volts, a reading of 0.0005 passes and 0.002 fails. Choose the allowance from the instrument's units and precision.
import numpy as np
np.isclose([0.0005,0.002],0,atol=0.001,rtol=0)Result [true, false]
中文
接近零的浮点读数怎样设置比较容差?
isclose 的绝对容差和相对参考值的容差共同决定是否足够接近。参考值为零时仅剩绝对容差。
numpy.isclose 算例
在允许偏差 0.001 伏时,0.0005 伏通过,0.002 伏超界。容差应来自仪器单位和精度。
import numpy as np
np.isclose([0.0005,0.002],0,atol=0.001,rtol=0)结果 [true, false]