de></pre>
<p>NumPy的版本要比它快过100倍。我们可以转换这个函数为编译的Numba函数，使用numba.jit函数：</p>
<pre><code>In [213]: import numba as nb

In [214]: numba_mean_distance = nb.jit(mean_distance)</code></pre>
<p>也可以写成装饰器：</p>
<pre><code>@nb.jit
def mean_distance(x, y):
    nx = len(x)
    result = 0.0
    count = 0
    for i in range(nx):
        result += x[i] - y[i]
        count += 1
    return result / count</code></pre>
<p>它要比矢量化的NumPy�