擅长:python、mysql、java
<p>在<code>numpy.testing</code>(源<a href="https://github.com/numpy/numpy/blob/1225aef37298ec82048d0828f6cb7e0be8ed58cc/numpy/testing/utils.py#L513" rel="noreferrer">here) </a>)中有一个函数<code>assert_approx_equal</code>,这可能是一个很好的起点。</p>
<pre><code>def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=True):
"""
Raise an assertion if two items are not equal up to significant digits.
.. note:: It is recommended to use one of `assert_allclose`,
`assert_array_almost_equal_nulp` or `assert_array_max_ulp`
instead of this function for more consistent floating point
comparisons.
Given two numbers, check that they are approximately equal.
Approximately equal is defined as the number of significant digits
that agree.
</code></pre>