IPython
A multi-language architecture for interactive computing
%pylab inline
%run talktools
Populating the interactive namespace from numpy and matplotlib
Hamming '62
import scipy.special as spec
x = linspace(0, 20, 200)
for n in range(0,13,3):
plot(x, spec.jn(n, x), label=r'$J_{%i}(x)$' % n)
grid()
legend()
title('Bessel Functions are neat');
@interactive(x=(1, 10))
def f(x):
print 'X is:', x
X is: 5
from sklearn import datasets
digits = datasets.load_digits()
n = len(digits.images)
@interactive(i=(0,n-1))
def view_image(i):
print 'Classif. Label:', digits.target[i]
plt.matshow(digits.images[i], cmap=cm.gray_r)
plt.show()
Classif. Label: 8
Image('fig/logo.png')
Video('fig/animation.m4v') # Credit: Chris Kees, Army ERDC; created with Proteus.
plot_audio('voice.wav')
Audio('voice.wav')
voice.wav:
Math(r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx')
from sympy import symbols, Eq, factor, init_printing, expand
init_printing(use_latex=True)
x, y = symbols("x y")
eq = ((x+y)**3 * (x+1))
display(Eq(eq, expand(eq)))
@interactive(n=(1,10))
def _(n):
eq = ((x+y)**n * (x+1))
display(Eq(eq, expand(eq)))
X = np.array([0,1,2,3,4])
Y = np.array([3,5,4,6,7])
# Now, load R support
%load_ext rmagic
%%R -i X,Y -o XYcoef
XYlm = lm(Y~X)
XYcoef = coef(XYlm)
print(summary(XYlm))
par(mfrow=c(2,2))
plot(XYlm)
Call: lm(formula = Y ~ X) Residuals: 1 2 3 4 5 -0.2 0.9 -1.0 0.1 0.2 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 3.2000 0.6164 5.191 0.0139 * X 0.9000 0.2517 3.576 0.0374 * --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 0.7958 on 3 degrees of freedom Multiple R-squared: 0.81, Adjusted R-squared: 0.7467 F-statistic: 12.79 on 1 and 3 DF, p-value: 0.03739
%load_ext julia.magic
%julia @pyimport matplotlib.pyplot as plt
%julia @pyimport numpy as np
Initializing Julia interpreter. This may take some time...
%%julia
# Note how we mix numpy and julia:
x = linspace(0,2*pi,1000); # use the julia linspace
y = sin(3*x + 4*np.cos(2*x)); # use the numpy cosine and julia sine
plt.plot(x, y, color="red", linewidth=2.0, linestyle="--")
[Line2D(_line0)]
jfib = %julia jfib(n, fib) = n < 2 ? n : fib(n-1, jfib) + fib(n-2, jfib)
def pyfib(n, fib):
if n < 2:
return n
return fib(n-1, pyfib) + fib(n-2, pyfib)
pyfib(20, jfib) # Credit: Steven Johnson, MIT.
%load_ext fortranmagic
%%fortran
subroutine f1(x, y, n)
real, intent(in), dimension(n) :: x
real, intent(out), dimension(n) :: y
!intent(hide) :: n
y = sin(x**2)
end subroutine f1
x = np.linspace(0, 2*pi, 300)
plot(x, f1(x));
website('nbviewer.ipython.org')
website('http://www.nature.com/ismej/journal/v7/n3/full/ismej2012123a.html', 'Paper:')
website('http://qiime.org/home_static/nih-cloud-apr2012', 'Companion Website:')
website('http://jakevdp.github.io/blog/2013/12/05/static-interactive-widgets',
'Pythonic Perambulations')
IPython.parallel
¶YouTubeVideo('tlontoyWX70',start='800', width=600, height=400)
Python for Signal Processing, By Jose Unpingco
|
website('camdavidsonpilon.github.io/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers',
'Probabilistic programming...')
|
website('http://cs109.org/homework/homework.php', 'CS 109 Homeworks')
IPython.parallel
¶website('http://nbviewer.ipython.org/gist/jackparmer/7729584', 'Rosling Countries',
width=900, height=600)
Plus Jonathan Frederic and Zach Sailer!
Many more! (~220 commit authors)
YouTubeVideo('UUjTAq8cCcs', width=600, height=500)
Note: We're hiring! Machine learning web pipelines for time-series analysis (astro, geo, neuro). With Josh Bloom (UCB Astro), NSF funding. Talk to me!