SHIFT+J , SHIFT+K Highlight up & Down (then copy,cut,paste)
SHIFT+M Merge highlighted cells
iPython Magic
Magic commands in ipython are also available in Jupyter
help
%lsmagic - List magic commands
%magic_command? - Help on specific magic_command
%env
Set environment variables
1
2
3
4
# Running %env without any arguments
# lists all environment variables# The line below sets the environment
# variable
%envOMP_NUM_THREADS%envOMP_NUM_THREADS=4
1
env:OMP_NUM_THREADS=4
%run
Execute python code from external .py file AND other jupyter notebooks
%run is not the same as importing a python module
1
2
3
# this will execute and show the output from
# all code cells of the specified notebook
%run./two-histograms.ipynb
%load
Insert script from an external file;
1
2
# Before Running
%load./hello_world.py
1
2
3
4
# After Running
# %load ./hello_world.py
if__name__=="__main__":print("Hello World!")
1
HelloWorld!
%who
List all variables in global scope
1
2
3
4
5
6
one="for the money"two="for the show"three="to get ready now go cat go"%whostronethreetwo
Timing
Two useful commands for timinig %%time, %%timeit and %timeit
1
2
3
4
5
6
%%timeimporttimefor_inrange(1000):time.sleep(0.01)# sleep for 0.01 seconds
CPUtimes:user21.5ms,sys:14.8ms,total:36.3msWalltime:11.6s
For %%timeit python uses timeit module , takes the average of 100K runs