IPython

2001, instead of a Physics dissertation (I did graduate :)

In [1]:
%pylab inline
%run talktools
Populating the interactive namespace from numpy and matplotlib

November 2001: "Just an afternoon hack"

  • 259 Line Python script.
  • sys.ps1 -> In [N].
  • sys.displayhook -> Out[N], caches results.
  • Plotting, Numeric, etc.

Now, IPython 2.0 (Ohloh stats)

  • 15,762 commits
  • 337 contributors
  • Total Lines : 151,353
    • Code Lines : 85,066
    • Comment Lines : 39,905
  • Number of Languages : 6 (JS, CSS, HTML, ...)
In [2]:
import ipythonproject; ipythonproject.core_devs()

IPython Core Developers

Fernando Perez
Brian Granger
Min Ragan-Kelley
Thomas Kluyver
Matthias Bussonnier
Jonathan Frederic
Paul Ivanov
Damian Avila
Kyle Kelley
Zach Sailer
Jorgen Stenarson
Jonathan March
Brad Froehle
Evan Patterson
Robert Kern

Current IPython funding

150K LOC for exec src in user_dict???

What can the official kernel do?

In [3]:
import mpld3; mpld3.enable_notebook()   # Jake van der Plas is here
import pandas as pd                     # Wes McKinney is here

pd.read_csv('MSFT_2000_2002.csv').plot();
/home/fperez/usr/opt/lib/python2.7/site-packages/mpld3-0.0.2-py2.7.egg/mpld3/_objects.py:414: UserWarning: Ignoring legend element: <matplotlib.offsetbox.VPacker object at 0x3fd3e90>
  warnings.warn("Ignoring legend element: {0}".format(child))
In [4]:
mpld3.disable_notebook()  # performance is still a little low, turn off for the rest

Mix and match languages: Julia

In [5]:
%load_ext julia.magic
%julia @pyimport matplotlib.pyplot as plt
%julia @pyimport numpy as np
Initializing Julia interpreter. This may take some time...
In [6]:
%%julia
# Note how we mix numpy and julia:
t = linspace(0,2*pi,1000); # use the julia linspace
s = sin(3*t + 4*np.cos(2*t)); # use the numpy cosine and julia sine
fig = plt.gcf()  # **** WATCH THIS VARIABLE ****
plt.plot(t, s, color="red", linewidth=2.0, linestyle="--")
Out[6]:
[<matplotlib.lines.Line2D at 0x3ff8c90>]

Deep cross-language integration

In [7]:
fig = %julia fig
fig
Out[7]:

The stack as a layer cake

In [8]:
fib = %julia fib(n, fib2) = n < 2 ? n : fib2(n-1, fib) + fib2(n-2, fib)
    
def fib2(n, fib):
    print 'Into Python, n=',n,
    if n < 2:
         return n
    print 'Out to Julia'
    return fib(n-1, fib2) + fib(n-2, fib2)

fib2(6, fib)
Into Python, n= 6 Out to Julia
Into Python, n= 4 Out to Julia
Into Python, n= 2 Out to Julia
Into Python, n= 1 Into Python, n= 1 Into Python, n= 0 Into Python, n= 3 Out to Julia
Into Python, n= 1 Into Python, n= 0 Into Python, n= 3 Out to Julia
Into Python, n= 1 Into Python, n= 0 Into Python, n= 2 Out to Julia
Out[8]:
8

Exploring values in an image

In [9]:
plt.rcParams['image.interpolation'] = 'nearest'
plt.gray()

img = randn(100,100)
plt.imshow(img);

Can we threshold interactively?

In [10]:
from IPython.html.widgets import interact

interact(lambda threshold: imshow(img < threshold), threshold=(-2, 2.));

Example credit: Michael Aye

Spreadsheets? Who needs spreadsheets?

In [11]:
%run handsondf.py
data = np.random.randint(size=(3, 5), low=0, high=9)
ds = DataSheet(data)
In [12]:
ds
Out[12]:
0 1 2 3 4
0 8 0 8 1 2
1 8 4 7 0 8
2 2 0 0 3 6

Credit: Cyrille Rossant

In [13]:
ds.edit()
In [14]:
ds
Out[14]:
0 1 2 3 4
0 8 0 8 1 2
1 8 4 7 0 8
2 2 0 0 3 6
In [15]:
ds.df.plot();

Javascript gets a brain

D3.js with a live Python kernel

A simple and generic architecture

Kernels, they are everywhere!
  1. IPython "Official", we ship it.
  2. IJulia
  3. IHaskell
  4. IFSharp
  5. IRuby
  6. IGo
  7. IScala
  8. IMathics
  9. IAldor
  10. IRKernel: Leaflet routing in R
  11. IErlang

Our web architecture:

Not just the notebook

The "Single cell" example