Introduction to NumPy Tutorial
This post originally appeared on the Software Carpentry website.
Today I did a tutorial moving quickly through the basic usage of NumPy, the essential library for doing numeric computing with Python. We covered building arrays; indexing; array math; NumPy's element-wise functions; array attributes and methods; random numbers; masked arrays; and array comparison.
I presented using the IPython HTML Notebook. I enjoyed it because I never had to switch between a terminal and text editor, but I wonder what the people viewing thought. A nice feature of the notebook is that I can export it, both as a PDF and in the .ipynb format importable by IPython. The PDF is here, and the .ipynb file here.
One thing we didn't cover was input/output. NumPy has functions for loading data from/saving to text files, and functions for saving to/loading from special NumPy binary files. The latter are useful for saving intermediate results. I've previously discussed numpy.loadtxt and numpy.genfromtxt on my personal blog.
One question I got was for advice for people switching from Matlab. I've never really used Matlab so I can't answer that question, but I found a relevant page on scipy.org: NumPy for Matlab Users.