Jupyter Notebook for Python
Jupyter notebook is a software (web application) that facilitates sharing interactive documents, referred to as jupyter notebooks. We will use these notebooks to learn Python.
Installing Jupyter and Getting Started
After installing Python and virtualenv, let's create an environment for our Python projects:
cd ~/Dropbox virtualenv --python=python3.6 HFFE cd HFFE source bin/activate # or .\Scripts\activate on Windows PowerShell
Now we will install all the packages we will use:
pip install -U pip # update pip installer pip install numpy # library for math (matrices, linear algebra) pip install matplotlib # library for plotting pip install jupyter pip install tensorflow # facilitates machine learning
Now we are ready to launch Jupyter.
Running the code below in the terminal will start the jupyter notebook process and launch a web browser with the application.
You can use this application to open .ipynb files, write text and run Python commands interactively.
jupyter notebook
Now, download the python-basics.ipynb file and put it in the ~/Dropbox/HFFE/ folder we just created.
Go to the Jupyter application in the web browser and you should see the file there.
You can now click on it to have it open on a separate tab.
The file contains a mix between text and code, and you can type and run code in it.
Jupyter Basic Shortcuts
The notebook is interactive and has 2 modes (with different shortcuts): Command Mode and Edit Mode. In the Command Mode you can use keyboard shortcuts to move around, create and delete cells (the boxes that hold text or code), and run code. In the Edit Mode you can edit the cells, type text or python commands and also run code.
Here is a summary of the commands:
| Command Mode | Edit Mode |
|---|---|
| Move between cells, edit and run code. | Type text and Python code. |
| Text can use the Markdown markup language. | |
| go to Edit Mode: RET | go to Command Mode: Esc |
| move from Cell to Cell: Arrow Keys | move around within cell: Arrow Keys |
| add Cell Above: A | |
| add Cell Below: B | |
| delete Cell: D D | |
| Change cell type to Code: Y | |
| Change cell type to Text: M | |
| Indent: Command ] | |
| Undent: Command [ | |
| Comment: Command / | |
| Delete Line: Command D | |
| Undo: Command Z | |
| Redo: Command Shift Z |