擅长:python、mysql、java
<p>你有点捉襟见肘。您需要GIL来调用<code>numpy.searchsorted</code>,但是GIL阻止任何类型的并行处理。最好的办法是编写自己的<code>nogil</code>版本<code>searchsorted</code>:</p>
<pre><code>cdef mySearchSorted(double[:] array, double target) nogil:
# binary search implementation
for j in prange(0,N, nogil=True):
for k in range(A2.shape[0]):
for L in range(A2.shape[1]):
C[j, k, L] = mySearchSorted(A1[j, :], A2[k, L])
</code></pre>
<p><code>numpy.searchsorted</code>也有非常多的开销,因此如果N很大,那么使用您自己的<code>searchsorted</code>来减少开销是有意义的。在</p>