Introduction to Scientific Computing with Python

This webpage/ipython notebook is for students (and others) who want to learn how to use Python for computations that arise in engineering and scientific problems.

Python is a fantastic language for scientific computing. It isn't Matlab, or Mathematica, or Maple, or R, but has features of all of them. Python is clearly on track to be the platform of choice for open source computing.

Get Python and Lots of Libraries

Python is a simple and general purpose language. By itself, it isn't too useful. But it becomes very powerful when combined with many libraries, covering all sorts of things.

While you can try to install Python and then lots of libraries one at a time, it is easiest (and likely best) to install a "batteries included" package. I can recommend the following packages:

  • Canopy. This is the package I use. It comes with lots of libraries (more than 100). It's free to academic users, but you have to ask for an academic license from Enthought.

  • Anacoda. This is newer than Canopy (I started with Canopy before Anaconda was available). Lots of people recommend Anaconda. It is free without any license issues and has lots of libraries.

Unfortunately it does not seem possible (at least on my Mac) to run both Canopy and Anaconda on the same machine (to test them out). They seem to conflict with each other.

Necessary Libraries

Here is a brief list of libraries we need. All of these libraries are included in Anaconda and Canopy:

  • ipython is an enhanced python shell. We use it two different ways:

    • as an enhanced python shell. I never run the standard python shell; I always run ipython. Ipython has a better command memory and feature system and allows "shell-like" commands like "ls", "cd", and "pwd".

    • the ipython notebook. The Ipython Notebook is an outstanding addition to the python arsenal. You must understand and use the ipython notebook. It allows the inclusion of text, multimedia, code, and output in the same file.

  • numpy gives python vectors and matrices (both called "arrays" in numpy). The syntax is close to, but not identical, to Matlab's matrix syntax.

  • scipy adds many numerical library functions, a la Matlab's tooboxes. Some interesting scipy libraries are the following:

    • scipy.signal adds many Matlab-style signal processing functions, e.g., filter design, Fourier transforms, etc.

    • scipy.linalg adds linear algebra functions, e.g., least squares, eigenvalue/eigenvectors, etc.

    • scipy.special adds special functions, e.g., Bessel functions, error function, etc.

  • matplotlib (also known as pylab) gives Matlab-style plotting routines.

Some additional libraries after the ones above are mastered:

  • pandas provides data manipulation routines. If your data looks like a table (various rows with named columns) then you probably want to consider pandas.

  • scikits.learn is widely used for classification problems. Most Kaggle competitors use python and scikit.learn.

  • statsmodels provides data fitting (linear regression) routines.

  • sympy does symbolic manipulation (algebra) like Maple or Macsyma.

Running IPython Notebooks Online

I am aware of two online services for running IPython notebooks. I.e., these do not require you to have a running IPython interpreter locally.

  • wakari.io Run by the same people that provide the Anaconda distribution.

  • SageMathCloud Part of the Sage project, SageMathCloud provides an online environment for running Sage and IPython code.

Note, while I have tried both, I haven't used either of these services enough to endorse them. At this point, I merely note they exist.

Tutorials

There are many tutorials available on the web. I am a big believer in the ipython notebook. These are ipython notebook based tutorials:

  • Johansson's Lectures These are a series of Ipython notebooks on python, ipython, numpy, scipy, matplotlib, sympy, and others. These tutorials are a must. Read them, do them, change the code and see what happens.

  • Gallery of Interesting Ipython Notebooks Many Ipython notebooks, on many subjects.

  • Wakari Gallery The Johansson lectures and a few others.

  • Boncelet's Ipython Gallery I've started my own gallery of IPython notebooks, focusing mostly on two topics: (1) Probability, Statistics, and Data Analysis, and (2) Digital Signal Processing. The gallery is small now, but I will be adding more over time.

Video Tutorials

There are lots of video tutorials out there. Here are some links:

  • Pyvideo.org Lots of videos, indeed thousands of videos. Pay attention to the videos of talks (especially the tutorials) from recent python oriented conferences, e.g., Scipy 2013 and Scipy 2014.

  • Scipy Conferences You may want to get the Scipy talks directly from here.

Other Tutorials


Charles Boncelet
boncelet@udel.edu
27 August 2014