ipython notebook vs. python script


In [4]:
import numpy as np

n = 5
x = np.arange(n)
y = np.zeros(n)
for i in range(n):
    y[i] = x[i]*x[i] 
z = x*x
print(x)
print(y)
print(z)


[0 1 2 3 4]
[  0.   1.   4.   9.  16.]
[ 0  1  4  9 16]

In [5]:
import matplotlib.pylab as plt
plt.plot(x,y)
plt.plot(x,z)
plt.show()

converting this notebook to a python script

When you run this notebook it will pop up a simple plot. You can save this notebook (.ipynb file) as a python script and run it from the unix command line as follows:

python mymath.py

or if you edit this file and as first line add

#! /usr/bin/env python

and make this script executable

chmod +x mymath.py

you can then run it as follows:

./mymath.py

In [ ]: