Using Python for Scientific Computation (Pythonを科学技術計算に使う)

注) このページは色々考えて英語にしました。


Matlab sucks because it is too expensive for students and even for professional researchers who have not enough funding (like me :-). Actually, Mathworks offer a cheap student version of Matlab+some toolboxes for $200 or so. Therefore, the financial problem is more serious for researchers like me. That was the main motivation for me to start exploring possibilities of using Python as a replacement for Matlab. Over the past few months, I did some investigations and tests on Python and concluded that Python can be a replacement of Matlab in most cases, as far as my needs are concerned. Moreover, I found that Python surpasses Matlab in many aspects, so it is not just a Matlab replacement but much more. Now I'm migrating from Matlab to Python rapidly. This page is intended to be a place to dump some know-hows on using Python as a scientific/technical computation platform.

What is Python

Want to know what the heck is Python ? Read Wikipedia

Setting up a working environment


It is very important for me to prepare a comfortable and efficient working environment before using a programing language. Python can be used in various ways. Python's core is its interpreter. So you can write a program using your favorite editor and pass the file to the Python interpreter. However, this may not be the best way to do scientific computation. While you are examining your experimental data and tweaking it, interactive session is often useful and powerful.

Matlab provides such a capability through its own IDE (Integrated Development Environment). Python interpreter can also be invoked in interactive mode, but it is not that useful by itself. There are several Python IDEs which provide similar look & feel to the Matlab IDE. IDLE is a python IDE distributed with the standard python package. Wikipedia has a list of Python IDEs. You can choose whichever one you like to do your Python programing. At the moment, Spyder seems to be the most Matlab like IDE for Python.

Using Python with Emacs

As for myself, I don't like those IDEs for not well defined reasons. My default editor is Emacs and I feel comfortable doing everything in Emacs. So I decided to use Emacs as my Python development environment. Actually, I used to use Matlab from Emacs. Therefore, using Python through Emacs is a natural move for me.

A nice feature of Matlab standard IDE is the cell. You can divide a script into several parts (cells) by putting dividers (%%) in the file. Then you can execute each cell by pressing Ctrl-Enter with the cursor in a cell. This way, you can execute a small portion of a long script without executing the whole script. This is useful, for example, when you have a long calculation and just want to change the appearance of the plot at the end.
I also like the cell of Mathematica notebook, where you can have nested (hierarchical) cells. You can also open and close cells to improve the readability of a long script. I don't know if any of the Python IDEs listed in the Wikipedia page has such a functionality but I knew that with Emacs, you can easily create such a function using Emacs Lisp. Therefore, I added a cell functionality to python-mode.el. If you are interested in my Emacs-Python environment, read this.

The above tutorial applies mainly to linux users, but Windows users should be able to do the same thing, in principle, as Emacs now works fine on Windows. I don't know anything about Mac, but Carbon Emacs may work.

Windows and Python

For Windows users, there are two easy ways to install Python and scientific extensions at once without a hustle. One is Enthought Python Distribution (EPD) and the other one is python(x,y).

EPD is a commercial product. However, for academic use, it is free. Go to the download page of the EPD website. At the bottom, you will find a link to academic version. You must enter your valid email address with a domain name of an academic institute (i.e. an email address ends with ""). The academic version of EPD is available in 64bit for all platforms. EPD is also available for Mac, Linux and Solaris.

python(x,y) is available for Windows and Linux. python(x,y) is free for everyone. However, it provides 32bit version only at the moment.

A bit more detailed explanation of how to install EPD and Spyder is here.


numpy basics


Signal Processing

Online Resources

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2013-07-09 (火) 14:50:24