Monday, October 4, 2021

Jupyter IDE lesson

 It's sometimes called IPython notebook.

Jupyter notebook is an IDE:

  • Integrated Development Environment
  • Syntax highlighting
  • debugging
  • code completion
  • embedded help documentation
  • introspection (i.e., you can check each command’s parameters)
  • in-line display of charts and images
I chose to install Anaconda because I have the space available and don't want to go searching for libraries later. 

Look! It's my first Jupyter file! 


Apparently you code in "cells" and you run them independently of each other... how in the world?!?!?!?!

Yes, I did the obligatory "Hello world" in Jupyter! :) Check out my first coding in Jupyter! 


Generalized help function with the question mark. You can type something you want help with and add a question mark and it will print out a small help file, such as:


First I created an error on purpose, then I learned how to debug using %debug in the next cell:


To debug, you type in the individual elements in the ipdb> line and it will tell you whether that is the problem. You exit the debugger by typing exit().

Now there is some info about markdown, but I'm already overwhelmed and will skip it for now. (forgive me) Here's the guide for later: Markdown guide.

Hotkeys in Jupyter Notebook. Accessible through help>keyboard shortcuts. Also ctro + shift + P to open the command palette. Here are some basic commands:
  • Basic navigation: EnterShift-EnterUp/kDown/j.
  • Saving the notebook: s.
  • Change Cell types: m to change the current cell to Markdown, y to change it back to code.
  • Cell creation: a to insert a new cell above the current cell, b to insert a new cell below.
  • Cell editing: xcvdz
  • Delete Current Cell: d + d (press the key twice).
  • Kernel operations: i0 (press twice).
  • Split the current cell into two: Ctrl + Shift + -.
  • Find and replace on your code: Esc + f
  • Toggle cell output: Esc + O

LaTeX - is a way to make math equations look good! That will have to be explored later too. Too overwhelming right now. 

Magic commands in Jupyter Notebook:
  1. line magic is a single percent symbol % prefix and only works on one line of output
  2. cell magic is a double percent symbol %% prefix and works on multiple lines of input
Some examples are:
  • %lsmagic - Return a list all magic command
  • %run: Execute external python script
  • %load: Load in a local file, URL, function, or class
  • %who: Return a list of any variables that have a certain type within the notebook.
  • %matplotlib notebook: Allow you to interactively work with plots from matplotlib.
  • %matplotlib inline: Allow you to disable interactivity with plots.
  • %%time: Show the time it took to execute the line of code. Good for checking efficiency.
Finding help: The question mark ? before the method or variable will print the help docs.

Suppress output and show only plot: end with semicolon.

Select more than one row: alt + mouse click

I am currently scared and overwhelmed with all this info. Here's the Jupyter user manual for later reference. 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Strings

A string consists of characters inside 'single quotes' or "double quotes". It can be any length and can contain letters, ...