A Jupyter sheet is made up of cells that you can guess if you click on the text. There are different cell types that you choose with the drop-down menu in the middle of the icons at the top of the page:
You can add
a cell with the + symbol at the top of the page, delete a cell with the scissors, move a cell with the arrows and edit it by double-clicking on it. We will see that we execute the cells to obtain the result of the written code. All this can be found on the menu
Cell
.
Jupyter takes its name from 3 languages, namely Julia, Python and R. Today the list of languages that can be
to use in a Jupyter sheet is much longer but in all cases you need a kernel which makes the interface
between Jupyter and the language. In the case of Python the core is iPython. We choose it when creating the sheet
and we can interact with it using the Kernel
menu.
The other menus are more classic and do not require explanation (forget Widget
).
If you do not know Python or Jupyter, it is advisable to come back here after reading the first chapter .
[out]
To hide the results, end the last line of the cell with ;
.[In]
To hide a cell, use 'Hide input' from nbextessions (see config in the Edit menu).print(2)
1+1; # remove the ; to see the difference
Jupyter has many commands to manipulate your note sheet and of course it is possible to set keyboard shortcuts.
To display the list of commands (the command palette) click on the small keyboard in the icon bar. With Chrome, you can display this command palette with Ctrl+Shift+P.
To display and define your keyboard shortcuts you can go to the help menu or type shortcut
in
the command palette.
For example, for my use I redefined the cell type change with
This works when the cell is selected but not in edit mode (so blue frame or blue bar).
Choose your shortcuts to switch from one mode to another then switch the cell below to Code mode and execute it.
print('$qsD!Me+nsodd= 1l lre3W$'[-2:2:-2])
Cell manipulation shortcuts are good to know or redefine when you start using Jupyter seriously.
When using Python in Jupyter, we rely on IPython which enriches Python.
This gives the following functionality:
?
and ??
for even more help with objects (or even code)!
a
Tab will give a list including abs
a
For the help examples, you must launch the cells to see the result.
abs?
To close the help window click on the cross at the top right of the window or use Esc.?
mot = "Coucou"
mot.split?
!pwd
vlib = '/var/lib/'
res = !ls $vlib
res = res.grep('lib')
for f in res:
print(f)
print(type(res))
res??
Magic commands improve the use of Python. They start with
%
and apply to the line%%
and apply to the cell (when it makes sense)The first magic command to run is %quickref
to get the list of iPython possibilities.
%quickref
Here is a selection of some magic commands:
%time
to get the time the line takes (%%time
for the execution time of the cell).%timeit
is like %time
but it restarts the line several times to get a more accurate estimate%prun
to run the line through the Python profiler and see where it's taking time%matplotlib inline
so that the graphs are displayed in the Jupyter page%load
to load a Python file into the cell (comments %load once executed)!echo 'print("coucou")' > /tmp/prog.py
%load /tmp/prog.py
import numpy as np
import scipy.linalg as lin
%prun lin.solve(np.random.random([3000,3000]), np.random.random(3000))
{{ PreviousNext('Introduction.ipynb','../lesson1 Python basics/00 - Premiers calculs.ipynb') }}