擅长:python、mysql、java
<p>至少使用numba 0.24,你可以做一个简单的投射:</p>
<pre><code>import numpy as np
import numba as nb
@nb.jit(nopython=True)
def need_a_cast(sources, indices, destinations):
for i in range(indices.size):
destinations[i] = sources[int(indices[i])]
sources = np.arange(10, dtype=np.float64)
indices = np.arange(10, dtype=np.float64)
np.random.shuffle(indices)
destinations = np.empty_like(sources)
print indices
need_a_cast(sources, indices, destinations)
print destinations
# Result
# [ 3. 2. 8. 1. 5. 6. 9. 4. 0. 7.]
# [ 3. 2. 8. 1. 5. 6. 9. 4. 0. 7.]
</code></pre>