-
Book Overview & Buying
-
Table Of Contents
IPython Interactive Computing and Visualization Cookbook - Second Edition
By :
NumExpr is a package that can offer some speedup on complex computations on NumPy arrays. NumExpr evaluates algebraic expressions involving arrays, parses them, compiles them, and finally executes them, possibly on multiple processors.
This principle is somewhat similar to Numba, in that normal Python code is compiled dynamically to machine code. However, NumExpr only tackles algebraic array expressions rather than arbitrary Python code. We will see how that works in this recipe.
NumExpr should already be installed in Anaconda, but you can also install it manually with conda install numexpr.
Let's import NumPy and NumExpr:
>>> import numpy as np
import numexpr as neThen we generate three large vectors:
>>> x, y, z = np.random.rand(3, 1000000)
Now, we evaluate the time taken by NumPy to calculate a complex algebraic expression involving our vectors:
>>> %timeit x + (y**2 + (z*x + 1)*3) 6.94 ms...
Change the font size
Change margin width
Change background colour