Stefan Boos

My personal GitHub pages

Follow me on GitHub

Jupyter Notebooks

Table of Contents generated with DocToc

Tutorials

Keyboard Shortcuts

Key Function
Enter Toggle ‘‘edit mode’’ for active cell
Shift+Enter '’Run’’ active cell and ‘‘move’’ to next
Ctrl+Enter '’Run’’ active cell and ‘‘stay’’ there
Tab Show available ‘‘completions’’
Shift+Tab Show ‘‘help’’ for command under cursor

Special Markdown

MathJax

MathJax Description
\(a = \frac{b}{c}\) $$a = \frac{b}{c}$$ defines a LaTeX formula rendered using MathJax. The formula is displayed centered.
$a = \frac{b}{c}$ $a = \frac{b}{c}$ defines inline LaTeX math. The formula is displayed inline with the text.

Magic Keywords

  • Start a line with % to include a magic keyword for the current line.
  • Start a line with %% to include a magic keyword for the entire cell.

Performance Analysis

Calculate the time a specific function call requires

%timeit my_function(arg1, arg2)

timeit

Calculate the time an entire cell requires

%%timeit
...
# cell contents
...

timeit for an entire cell

Including Plots into Jupyter Notebooks

%matplotlib inline

The parameter inline specifies that the “inline” backend shall render the diagram directly into the Jupyter window. If you omit that parameter, the diagram will be rendered into a new window.

On a retina display the rendered diagram can look blurry. To correct this, use

%config InlineBackend.figure_format = 'retina'

to render high resolution images.

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(20)
y = x**2

plt.plot(x, y)

Example by Udacity

matplotlib example

Matplotlib Tutorial

Debugging

Use the magic command

%pdb

to launch the debugger when the executed python script hits an error condition. Find the python debugger help page here.

To get the IPython debugging shell with syntax highlighting, add the following code to your cell:

from IPython.core.debugger import set_trace

def add_to_life_universe_everything(x):
    answer = 42
    set_trace()
    answer += x
    
    return answer

add_to_life_universe_everything(12)

References