Jupyter Notebook 入門級shortcuts 和 tips

Jupyter notebook is a sequential collection of cells. Cell can be in either Edit (green colored) & Command (blue colored) mode, and cell has Raw(R), Markdown(M), and Code(Y) types. 

Cell types can be selected when the cell is in Command mode. To escape from Edit mode to Command mode, hit the ESC key. Once in Command mode, can select the cell type with R, M, Y key.

  1. How to use Jupyter Notebook Remotely: Run your codes on a remote server, while displaying the Jupyter notebook on your local machine
    (1) On the server: cd into the project directory
    $ jupyter notebook --no-browser --port=8889
    (2) On your local machine:
    $ ssh -N -f -L localhost:8888:localhost:8889 username@your_remote_host_name
    (3) On your local machine, open a brower and go to http://localhost:8888
    (4) First time connection between the local and remote machines may requries a token verification:
    The brower will display a promot-up window asking for token, and the token can be found in your remote machine terminal after executing step (1).
    This token verification is only needed for the first time connection. Later connections just go over steps (1) - (3).

  2. Run cell:
    (1) If want to run all cells from the top to bottom altogether, go to the Toolbar-->Cell-->Run All;
    (2) If want to run a single cell:
    a. Shift + Enter: run the cell and initialize a new cell below; b. Ctrl + ENter: run the cell without initializing a new cell below.

  3. Insert a new cell:
    Select the cell above and escape to command mode with ESC, then hit B.

  4. Split a cell:
    Toolbar-->Edit-->Split Cell

  5. Clean up the running outputs of cells:
    (1) Cleaning all cells to prepare for a whole new run (if connect remotely, doing this will refresh the GPUs on the remote server):
    Toolbar--> Restart & Clear Output (2) Cleaning just one cell:
    In command mode (use ESC to get in command mode), hit R to change to Raw type, then switch back to code type with Y.

  6. Display line number in cells:
    Toolbar-->View-->Toggle Line Number

  7. Sometimes if directly compy&paste codes from a text editor, the indentation may be troublesome:
    Select the cell with problematic indentations, hit Tab to indent, then hit Shift + Tab to inverse indentation.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章