擅长:python、mysql、java
<p>首先我要避免被零除:</p>
<pre><code>if a == 0:
# Break out early
# Otherwise the ratio makes sense
</code></pre>
<p>如果您确实想在一行上压缩特定的numpy警告,numpy将提供<a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.errstate.html" rel="nofollow noreferrer">a way</a>:</p>
<pre><code>with numpy.errstate(divide='ignore'):
# The problematic line
</code></pre>