擅长:python、mysql、java
<p>你可以使用<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.isin.html" rel="nofollow noreferrer"><strong>^{<cd1>}</strong></a></p>
<blockquote>
<p><strong><code>isin</code></strong> is an element-wise function version of the python keyword <strong><code>in</code></strong></p>
</blockquote>
<pre><code>np.isin(a, vals_keep)
array([[False, True],
[ True, False]])
</code></pre>
<p><strong><code>isin</code></strong>的另一个好处是,它可以灵活地处理不同维度的数组:</p>
<pre><code>a = np.arange(4).reshape(1,2,2,1)
np.isin(a, vals_keep)
array([[[[False],
[ True]],
[[ True],
[False]]]])
</code></pre>