Download Introduction to Python for Science Contents

Transcript
Introduction to Python for Science, Release 1
6.4
Debugging strategies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
67
7
Profiling Python code
7.1 Timeit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.2 Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7.3 Line-profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
68
68
68
70
8
Advanced numpy
8.1 Broadcasting . . . . . . . . . . .
8.2 Views and strides . . . . . . . . .
8.3 Fancy indexing . . . . . . . . . .
8.4 Robert (Kern)’s nasty stride trick
.
.
.
.
71
72
75
79
82
pyflakes: fast static analysis
9.1 In kate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.2 In vim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.3 In emacs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
83
83
83
84
9
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Why Python
• Efficient coding: what is the point of very fast simulations, if it takes longer to write them than to run
them?
• Full-fledge, non-specialized, programming language.
• Communication: code should read like a book.
• Code that we understand: developing an intuition, an understanding of the algorithms through exploratory
coding and interaction.
Installing with distributions:
• EPD: http://www.enthought.com/products/epd.php
• Python(x,y): http://www.pythonxy.com
Resources
Simple
• In French Python for Science: http://dakarlug.org/pat/scientifique/html/index.html
• Videos http://www.archive.org/search.php?query=SciPy%202009%20tutorial
• The Python tutorial (excellent): http://docs.python.org/tutorial/
Advanced
• http://docs.scipy.org/
• Python Scripting for Computational Science, Hans Petter Langtangen, Springer
• Python Cookbook, David Ascher, Matt Margolin, Alex Martelli, O’Reilly
ii
Contents
1