Python for Scientists

Python is a popular computer scripting language. Its popularity is earned because it is open source and hence completely free as opposed to for example matlab, maple, or mathematica. To develop scientific software, the advantage of such interpreters is that they are very flexible in trying out several possibilities during the design stage of scientific software and they allow for an integration of numerical, algebraic, and graphical aspects of the problem. The downside is that they are usually rather slow. For production purposes, the software can better be implemented in a language like Fortran or C that can be compiled and that speeds up execution time considerably. These however are much less intuitive and more complex languages to learn. Python was developed in 1991 by Guido van Rossum (he was a big fan of Monty Python's Flying Circus), and has now become one of the most popular scripting languages. An army of volunteer developers have surrounded it with many modules (even compiled) that can be understood by Python and thus can be integrated while executing a Python program. Especially the numpy and matplotlib package has contributed substantially in the use of Python for scientific computing.

Of course already many books are available that introduce Python. So the question should be answered here in what sense this book differs from all the others. The target audience consists of students and researchers who are familiar with computers, programming, and numerical analysis, and Stewart wants to introduce them to the possibilities that Python can provide in their study or work. In this sense, it is complementary to Numerical Methods in Engineering with Python 3 where the prime focus was to give a numerical analysis course where Python was used as one of the possible tools, introducing only the minimal elements of the language. In the Stewart book the focus is the language, although there are some (rather extensive) numerical examples, but they are just case studies to illustrate the power of Python, with only a minimum of numerics introduced (which are assumed to be known anyway). One of the advantages of this book is that it is deliberately kept short. Only 232 pages for such a lot of information is not that much. It goes directly to the core that should interest the target reader. Ideally it is to be read hands-on the computer, and after reading and experimenting your way through it, you are supposed to be ready to start on your own and find your way in more elaborate programming manuals for Python, for example the excellent documentation on the Python site and the websites for the many add-on packages that are available on the Internet. No exercises are provided, so it is not really a course book, but the practitioner who wants to learn Python will love it. This is the type of book I have been looking for to learn Python.

An outline of the book is as follows. Installing Python and its packages is explained in an appendix, so that Chapter 2 can start with the introduction using the IPython interactive screen. Users of matlab, maple, or mathematica will be familiar with this: you type a command and Python immediately responds. There are some elementary examples and a lot of tips for beginners: how to get help, tab completion, automagic commands etc. This is a feature also of the following chapters: Stewart is always giving good advise for the Python novice, things you would not find in a thick formal manual. So the true tutorial starts with Chapter 3 by introducing the different types objects, identifiers, loops, tests, functions, I/O commands. The Python classes might be a bit less familiar to some readers not familiar with object oriented programming (OOP). However, this is not an OOP course and only just enough information is provided to get along. The examples are typical for scientists: Fibonacci, gcd, prime numbers. Numerical computations become only feasible with Chapter 4 where the numpy package is introduced. Now arrays and linear algebra with their basic numerical tools become available. With these elements, the numerically educated reader should be able to take up the slack and move on. The next two chapters are devoted to two- and three-dimensional graphics. There is a numpy interface with gnuplot but graphics of matlab quality are provided through the matplotlib package with the possibility to include for example LaTeX text or make animations. For the 3D graphics, an interface is needed to render 3D data on a 2D screen. There are different standards to do this and Stewart illustrates two of them: the mplot3d module of matplotlib or the mlab module from the mayavi package (the latter using a VTK standard). The Python programming is similar but obviously different and also the eventual rendering looks somewhat different. Apart from the numerics for the problem to be solved, the visualizing part takes often most of the programming lines. So Stewart has spent relatively much attention to these chapters.

Equipped with all this technical background, some more involved case studies are given in the second half of the book. Chapter 7 gives fully worked out examples for ordinary differential equations (initial and boundary value problems), delay differential equations and stochastic differential equations. Explaining the numerical methods is kept to a minimum. The focus is on the relevant modules to be loaded and the Python programming. The same is true for Chapter 8 dealing with partial differential equations. Here it is illustrated how (possibly precompiled) fortran programs can be imported in Python. Fortran is used as an example, but that could also have been C. The main purpose is to re-use existing software (e.g. fft) or speed up the time consuming number crunching parts. The final chapter illustrates how easily a multigrid code can be produced in Python by exploiting the agility of Python to deal with classes and with recursion.

Reviewer: 
Adhemar Bultheel
Book details

This is a concise, yet practical description of the Python language for scientists. It is assumed that the reader is familiar with computer programming via e.g. matlab, fortran or C. Especially the numerical package numpy and the plot package matplotlib get focus. The second half gives some nontrivial numerical cases where differential equations are solved in Python.

Author:  Publisher: 
Published: 
2014
ISBN: 
978-1107061392 (hbk)
Price: 
65,00 €
Pages: 
232
Categorisation