jupyter notebooks

The jupyter notebook (previously iPython) is an interactive computational environment, in which you can combine code execution, rich text, mathematics, plots and rich media.

Unlike running a Python script on the command line the code and results are stored together.


In [1]:
print ("Hello world")


Hello world

In [2]:
x = 1 + 1
print x
x


  File "<ipython-input-2-bc9376192379>", line 2
    print x
          ^
SyntaxError: Missing parentheses in call to 'print'

Variables created in one cell can be used in another


In [ ]:
y = x + 1
print y

Cells must be run in order for this to work


In [ ]:
a = 1

In [ ]:
b = a + 1
b

Document notebooks

Each cell can be code, markdown https://en.wikipedia.org/wiki/Markdown

Markdown can be used to add documentation to a notebook.

To change the cell type to markdown Ctrl-m m or click into the cell and select Markdown using the dropdown that defaults to code

Latex formulas

Using MathJax formulas can be added in markdown cells (this does not render 100% in Chrome)

$y = x$

$c = \sqrt{a^2 + b^2}$

$$3\left(\frac{2}{5}\right)$$
\begin{eqnarray*} 5x^2-9&=&x+3\\ 4x^2&=&12\\ x^3&=&3\\ x&\approx&\pm1.732 \end{eqnarray*}