Book Image

IPython Notebook Essentials

By : Martins
Book Image

IPython Notebook Essentials

By: Martins

Overview of this book

If you are a professional, student, or educator who wants to learn to use IPython Notebook as a tool for technical and scientific computing, visualization, and data analysis, this is the book for you. This book will prove valuable for anyone that needs to do computations in an agile environment.
Table of Contents (10 chapters)

IPython magics

Magics are special instructions to the IPython interpreter that perform specialized actions. There are two types of magics:

  • Line-oriented: This type of magics start with a single percent (%) sign
  • Cell-oriented: This type of magics start with double percent (%%) signs

We are already familiar with one of the magic command, that is, %pylab inline. This particular magic does two of the following things: it imports NumPy and matplotlib, and sets up the notebook for inline plots. To see one of the other options, change the cell to %pylab.

Run this cell and then run the cell that produces the plot again. Instead of drawing the graph inline, IPython will now open a new window with the plot as shown in the following screenshot:

IPython magics

This window is interactive and you can resize the graph, move it, and save it to a file from here.

Another useful magic is %timeit, which records the time it takes to run a line of Python code. Run the following code in a new cell in the notebook:

%timeit return_on_investment...