Cython: Working with NumPy

运行时间

方法 时间
convolve_py 409 ms ± 5.92 ms per loop (mean ± std. dev. of 3 runs, 2 loops each)
convolve1 305 ms ± 2.06 ms per loop (mean ± std. dev. of 3 runs, 2 loops each)
convolve2 329 ms ± 1.86 ms per loop (mean ± std. dev. of 3 runs, 2 loops each)
convolve3 2.27 ms ± 16.4 µs per loop (mean ± std. dev. of 3 runs, 2 loops each)
convolve4 681 µs ± 32.2 µs per loop (mean ± std. dev. of 3 runs, 2 loops each)

与教程不同的是,convolve2并没有减少运行时间。

tips

编译pyx时出错Cython: “fatal error: numpy/arrayobject.h: No such file or directory”

解决方法

In your setup.py, the Extension should have the argument include_dirs=[numpy.get_include()].

你可能感兴趣的:(Cython)