Jupyter Notebook#
Note
An old recording of a previous version of this can be found here.
Jupyter Notebook is a simplified notebook authoring application for interactive computing with computational notebooks. A computational notebook is a shareable document that combines computer code, plain language descriptions, data, rich visualizations like 3D models, charts, graphs and figures, and interactive controls. A notebook, along with an editor like Jupyter Notebook, provides a fast interactive environment for prototyping and explaining code, exploring and visualizing data, and sharing ideas with others. From: Jupyter Notebook
How to access the Science Jupyter Server#
navigate to https://jupyterhub22.science.ru.nl
login with your science user account
(eventually) start a new session by clicking “Spawn”
you’re done and ready to go!
Jupyter Notebooks Fileformat#
notebooks are saved as *.ipynb files
but can also be stored as *.py, *.pdf, etc.
Cells#
There are two main types of cells: code cells and markdown cells. Hit SHIFT+ENTER to execute the contents of a cell.
Markdown cells contain:
markdown
HTML
LaTeX
plain text
images
videos
Anything that a browser can understand
For more information about markdown see Markdown Basics on GitHub and Markdown Syntax.
Python code is written in code cells. Hit SHIFT+ENTER to execute the code. Output is displayed below the code cell:
# Python code to display the first 10 square numbers
for n in range(1,11):
print(n**2)
1
4
9
16
25
36
49
64
81
100
Modes#
There are two modes: edit mode and command mode. Press ESC to enter command mode and ENTER for edit mode.
Edit mode is for writing text and code in the cell.
Command mode is for notebook editing commands such as cut cell, paste cell, and insert cell above.
Keyboard Shortcuts#
The toolbar has buttons for common actions however you can increase the speed of your workflow by memorizing the following keyboard shortcuts in command mode:
Command Mode Action |
Shortcut |
|---|---|
insert empty cell above |
|
insert empty cell below |
|
copy cell |
|
cut cell |
|
paste cell below |
|
switch to code cell |
|
switch to markdown cell |
|
save and checkpoint |
|
execute cell |
|
See Help in the toolbar of the Jupyter notebook to see the list of keyboard shortcuts.
Ipython Helper (Magics)#
https://ipython.readthedocs.io/en/stable/interactive/magics.html
# python code -- get timings
%timeit 7.0 + 42.0
10.7 ns ± 0.107 ns per loop (mean ± std. dev. of 7 runs, 100,000,000 loops each)
# python code -- get help / docu to functions, etc.
?abs
?round