Minor changes to the original code did not get the job done, so we must consider more drastic approaches. Luckily, with Python, we have the NumPy
library. NumPy
provides a very fast n-dimensional array (called ndarray
) data structure for Python and offers a number of operations on this data type that have been implemented in C and are highly optimized.
Before we make any major changes to asa.py
, we use this recipe to try a few toy examples to see how much faster the NumPy
library's faster yet less flexible ndarray
arrays are versus naïve Python lists.
For this recipe, we only need to fire up the Python REPL or, even better, start up IPython. Also, this recipe assumes that you have NumPy
installed.