Skip to main content
What is Python? 
An overview of Python for science 
Nicholas Pringle
What is Python? 
Python1 is a 
● general purpose2, 
● high-level3, 
● free and open-source4, 
● readable and intuitive 
programming language which provides strong guidelines. 
It has been called the glue5, but is now becoming the swiss 
army knife, of scientific programming.
Why should we use it? 
It integrates well with other languages like R6, 
MATLAB7, C8 or FORTRAN9. 
¹³² 
It has a large community of users. 
It has mature and well documented scientific 
packages...
The scientific packages 
The most important packages are Numpy, 
SciPy and Matplotlib. 
Together these libraries allow one to use 
Python in a manner similar to MATLAB. 
They can be used with an IDE like Spyder...
Spyder 
Explore the 
variables 
here... 
2 
I can write my code here… 
(syntax errors are shown) 
1 
And investigate my data in an 
interactive terminal here… 
This includes plotting inline 
3
Numpy 
Support for large multidimensional arrays and 
matrices10 
Together with Scipy and Matplotlib attempt to 
provide MATLAB functionality. 
Or at least thats how it started...
Scipy 
Builds on Numpy and provides: 
● Signal processing 
● Linear algebra routines 
● Statistics 
● Optimization 
● Interpolation 
● and more...
Matplotlib... 
Has many plotting options and 
additional libraries like Basemap. 
[Gallery link]
What makes it so great? 
The size of the community means that it is easy to find a solution to your 
problem. Additionaly there are many great online courses. e.g. Coursera 
It is easy to learn and easy to read. 
Your code is generally cross-platform and not sensitive to package versions. 
My code is too - so we can share! Which is useful for things like downloading 
and cleaning data within an organisation. An automated workflow can be 
established.
The Python community 
Python users fall into 3 broad categories: 
● individual users 
o write their own scripts (statistical analysis of their data, creation of figures) 
● institutional users 
o are working on projects as a team 
o collaboration is very important 
o Need to provide products 
● scientific python developers 
o contribute to the scientific packages 
(from Van der plas, 2013)
The community is diverse 
● Astronomy [AstroPy] 
● Remote Sensing [Link, Link, Link] 
● Oceanography [Link] 
● Web development [Django] 
● Game Development 
● Finance (Data Analysis) 
● High Performance computing [ANL]
The community is fun 
You can make minesweeper animations… [Link] 
Or make XKCD style plots… [Link] 
Learn when to have your case favourably 
reviewed by a judge… [Link] 
Build a prediction engine for betting on horse 
races (and lose money) [Link] 
“Writing your own solution is a good indication that you 
don’t know what you’re doing...” - Nathan Taggart
What else does Python offer 
● IPython Notebook11 - executable code 
● Pandas12 - the new R 
● Scikit Learn13 - Machine Learning 
● Numba, Blaze - lightning fast, big data 
● Bokeh - plotting 
● Wakari - Python in the cloud
How to collaborate (lofty goals) 
● Use virtual environments which don’t rely on 
your system packages14 
● Use version control to keep track of 
development and to share15 
● Use PEP816 as a standard for readability 
● Try and fit your code to a MVC17 pattern 
● Write good test coverage18, 19
Python Scientific Distributions 
Python is easiest to use in a linux or unix environment. 
However, there are some very good all-in-one packages 
available. And they are free. 
● Enthought Canopy [Link] 
● Anaconda (I recommend) [Link] 
● or $ pip install in a virtualenv 
Python2 or Python3? 
You can use both but try for Python3.4 
Try one of them 
out today!
More slides… should there be time.
A simple example 
import numpy as np # imports the numpy package into the namespace 
from matplotlib import pyplot as plt # imports plotting from matplotlib 
def straight_line(m, x, c): 
y = m*x + c 
return y 
gradient = 2 
x_coords = np.arange(-10, 11) # create 1D array from -10 to 10 
y_int = -2 
line = straight_line(gradient, x_coords, y_int) 
plt.plot(x_coords, line) 
plt.grid()
What is python? 
Python is a general purpose, high-level programming 
language. 
General purpose: a wide variety of application domains 
High-level: it does the hard work for you
What else is Python? 
Python is a free and open source, so this guarantees end 
users (individuals, organizations, companies) the freedoms 
to use, study, share (copy), and modify the software. 
Python emphasizes code readability, so it is easy to 
understand ones own code and that of others. 
Additionally there are are quite strong guidelines which 
means everybody is on the same page.
Python is moving forward 
There are exciting packages being added at an alarming 
rate. 
Current packages are improving all the time. 
Continuum Analytics received $3 million in funding. 
There are great python conferences - EuroPy/EuroSciPy
Model, View, Controller 
MVC is a software architectural pattern for implementing user interfaces. Using this pattern can 
provide a solid foundation for collaboration. 
Model 
● HDF5, NETCDF4, PyTables 
View 
● PyQT, Matplotlib 
Controller 
● Numpy; Scipy, Pandas, etc...
Other resources 
Version control (Github) [Link] 
Using version control on anything you work on can save 
you a lot of trouble, it also makes working with other much 
simpler. [example] 
Stackexchange [Link] 
The stackexchange network is a group of Q&A forums 
where you can get help on a variety of topics.
More Links... 
Some key people in the python community: 
● Travis Oliphant [Link] 
● Jake Vanderplas [Link] 
● Wes McKinney [Link] 
● Randal Olson [Link]