2. SciPy科学类库

在 scipy 中,原本有 weave 模块,来使用 C++ 语言加快局部代码的运行速度。

Python作为动态语言其功能虽然强大,但是在数值计算方面有一个最大的缺点:速度不够快。在 Python级别的循环和计算的速度只有C语言程序的百分之一。因此才有了NumPy, SciPy这样的函数 库,将高度优化的C、Fortran的函数库进行包装,以供Python程序调用。如果这些高度优化的函数 库无法实现我们的算法,必须从头开始写循环、计算的话,那么用Python来做显然是不合适的。因此 SciPy提供了快速调用C++语言程序的方法– Weave。

这个模块后来独立出来,供 Python 2.x 使用。 对于新的代码, 推荐使用 Cython 。

Weave provides tools for including C/C++ code within Python code. Inlining C/C++ code within Python generally results in speedups of 1.5x to 30x over algorithms written in pure Python.

Weave is the stand-alone version of the deprecated Scipy submodule scipy.weave. It is Python 2.x only, and is provided for users that need new versions of Scipy (from which the weave submodule may be removed) but have existing code that still depends on scipy.weave. For new code, users are recommended to use Cython.