擅长:python、mysql、java
<p>您可以将<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.searchsorted.html" rel="nofollow noreferrer">^{<cd1>}</a>与<code>left</code>和<code>right</code>一起使用,并且只保留那些不同时返回相同索引的对象:</p>
<pre><code>>>> import numpy as np
>>> A = np.array([1,2,3,4,5,6,7,8,9,10.5])
>>> B = np.array([1,7,10])
>>> i = np.searchsorted(A, B, 'left')
>>> j = np.searchsorted(A, B, 'right')
>>> i[i!=j]
array([0, 6], dtype=int64)
</code></pre>
<p>这是因为<code>searchsorted</code>返回一个索引,如果您想对另一个数组进行排序,则需要在其中插入元素。因此,当值出现在另一个数组中时,它返回匹配前的索引(<code>left</code>)和匹配后的索引(<code>right</code>)。因此,如果索引不同,则存在完全匹配,如果索引相同,则不存在完全匹配</p>