Skip to main content

Jupyter notebooks

Tools​

Jupyter (= Julia + Python + R) notebooks are a way to build and prototype with code easily and quickly. They are available for multiple languages including Python.

They are made of cells that can contain code or documentation written in markdown format. They are a great way to teach people to code or a code specific concept as the code can be split into bit size piece that are executed independently.

The result of the execution of a piece of code is shown below. The result can be text in the case of a print statement or a graph or even an interactive demo or 3d plot.

Example of a piece of code that generates an interactive 3d plot using matplotlib.

%matplotlib widget
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt

ax = plt.axes(projection='3d')

# Data for a three-dimensional line
zline = np.linspace(0, 15, 1000)
xline = np.sin(zline)
yline = np.cos(zline)
ax.plot3D(xline, yline, zline, 'gray')

# Data for three-dimensional scattered points
zdata = 15 * np.random.random(100)
xdata = np.sin(zdata) + 0.1 * np.random.randn(100)
ydata = np.cos(zdata) + 0.1 * np.random.randn(100)
ax.scatter3D(xdata, ydata, zdata, c=zdata, cmap='Greens')

Because variables are shared between cells, they are useful when doing tasks that take a long time and require tweaking between runs (like fine-tuning, Fine-tuning).

You can edit jupyter notebook inside VSCode. They are simply files with the .ipynb extension. They are represented internally as JSON and can be commited into Git.

The result of the last execution of a cell is saved inside the notebook.

You can also edit and execute notebooks in the cloud using Google Collab