/ #python #jupyter 

Introduction to IPython & Jupyter Notebooks

IPython & Jupyter: An enhanced interactive Python shell; A decoupled two-process communication model, which allows for multiple clients to connect to a computation kernel, most notably the web-based notebook; An architecture for interactive parallel computing.


One of Python’s most useful features is its interactive interpreter. It allows for very fast testing of ideas without the overhead of creating test files as is typical in most programming languages. However, the interpreter supplied with the standard Python distribution is somewhat limited for extended interactive use.

IPython

IPython is an interactive shell that addresses the limitation of the standard python interpreter, and it is a work-horse for scientific use of python. It provides an interactive prompt to the python interpreter with a greatly improved user-friendliness.

It comes with a browser-based notebook with support for code, text, mathematical expressions, inline plots and other rich media.

You don’t need to know anything beyond Python to start using IPython – just type commands as you would at the standard Python prompt. But IPython can do much more than the standard prompt…

A comprehensive environment for interactive and exploratory computing

Three Main Components:

  • An enhanced interactive Python shell.
  • A decoupled two-process communication model, which allows for multiple clients to connect to a computation kernel, most notably the web-based notebook.

Some of the many useful features of IPython includes:

  • Command history, which can be browsed with the up and down arrows on the keyboard.
  • Tab auto-completion.
  • In-line editing of code.
  • Object introspection, and automatic extract of documentation strings from python objects like classes and functions.
  • Good interaction with operating system shell.
  • Support for multiple parallel back-end processes, that can run on computing clusters or cloud services like Amazon EC2.

IPython provides a rich architecture for interactive computing with:

  • A powerful interactive shell.
  • A kernel for Jupyter.
  • Easy to use, high performance tools for parallel computing.
  • Support for interactive data visualization and use of GUI toolkits.
  • Flexible, embeddable interpreters to load into your own projects.
  • An architecture for interactive parallel computing.

IPython QtConsole

  • a version of IPython, using the new two-process ZeroMQ Kernel, running in a PyQt GUI
  • a very lightweight widget that largely feels like a terminal, but provides a number of enhancements only possible in a GUI, such as inline figures, proper multiline editing with syntax highlighting, graphical calltips, and much more.

Jupyter Notebook

The Jupyter Notebook is a web application for interactive data science and scientific computing.

Using the Jupyter Notebook, you can author engaging documents that combine live-code with narrative text, equations, images, video, and visualizations. By encoding a complete and reproducible record of a computation, the documents can be shared with others on GitHub, Dropbox, and the Jupyter Notebook Viewer.

  • Open source, interactive data science and scientific computing across over 40 programming languages.
  • The Jupyter Notebook is a web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text.
  • Uses include: data cleaning and transformation, numerical simulation, statistical modeling, machine learning and much more.

  • Language of Choice: The Notebook has support for over 40 programming languages, including those popular in Data Science such as Python, R, Julia and Scala.

  • Share Notebooks: Notebooks can be shared with others using email, Dropbox, GitHub and the Jupyter Notebook Viewer.

  • Interactive Widgets: Code can produce rich output such as images, videos, LaTeX, and JavaScript. Interactive widgets can be used to manipulate and visualize data in realtime.

  • Big-Data Integration: Leverage big data tools, such as Apache Spark, from Python, R and Scala. Explore that same data with pandas, scikit-learn, ggplot2, dplyr, etc.

Up and Running

An IPython notebook lets you write and execute Python code in your web browser. IPython notebooks make it very easy to tinker with code and execute it in bits and pieces; for this reason IPython notebooks are widely used in scientific computing.

Once IPython is running, point your web browser at http://localhost:8888 to start using IPython notebooks. If everything worked correctly, you should see a screen showing all available IPython notebooks in the current directory.

If you click through to a notebook file, it will be executed and displayed on a new page.

An IPython notebook is made up of a number of cells. Each cell can contain Python code. You can execute a cell by clicking on it and pressing Shift-Enter. When you do so, the code in the cell will run, and the output of the cell will be displayed beneath the cell. See example.

Global variables are shared between cells. See the notebook after executing the second cell.

By convention, IPython notebooks are expected to be run from top to bottom. Failing to execute some cells or executing cells out of order can result in errors.

See: CS231n: IPython Tutorial

Author

Eueung Mulyana

Engineer. Lecturer. Programmer. Open Source Enthusiast.