擅长:python、mysql、java
<p>可以使用<code>numpy.ma.array</code>函数屏蔽数组,然后应用任何<code>numpy</code>操作:</p>
<pre><code>import numpy as np
a = np.random.rand(10) # Generate random data.
a = np.where(a > 0.8, np.nan, a) # Set all data larger than 0.8 to NaN
a = np.ma.array(a, mask=np.isnan(a)) # Use a mask to mark the NaNs
a_norm = a / np.sum(a) # The sum function ignores the masked values.
a_norm2 = a / np.std(a) # The std function ignores the masked values.
</code></pre>
<p>您仍然可以访问原始数据:</p>
<pre><code>print a.data
</code></pre>