!ls import random as rd %timeit sorted([rd.random() for i in range(10000000)]) /ord "A" 1+1 2+2 _i32 _33 %history %%writefile ipython_html.py class ListTable(list): """ Overridden list class which takes a 2-dimensional list of the form [[1,2,3],[4,5,6]], and renders an HTML Table in IPython Notebook. """ def _repr_html_(self): html = [""] for row in self: html.append("") for col in row: html.append("".format(col)) html.append("") html.append("
{0}
") return ''.join(html) import random table = ListTable() table.append(['x', 'y', 'x-y', '(x-y)^2']) for i in xrange(7): x = random.uniform(0, 10) y = random.uniform(0, 10) table.append([x, y, x-y, (x-y)**2]) table !ls ipython_html.py !cat ipython_html.py %pwd? %%ruby puts "Ruby is also an awesome language" %lsmagic from IPython.display import YouTubeVideo, ScribdDocument, Image YouTubeVideo("99dmQGPkvog") Image("http://imgs.xkcd.com/comics/python.png") ScribdDocument(57352264, width=800, height=400, start_page=3, view_mode="book") class ListTable(list): """ Overridden list class which takes a 2-dimensional list of the form [[1,2,3],[4,5,6]], and renders an HTML Table in IPython Notebook. """ def _repr_html_(self): html = [""] for row in self: html.append("") for col in row: html.append("".format(col)) html.append("") html.append("
{0}
") return ''.join(html) import random table = ListTable() table.append(['x', 'y', 'x-y', '(x-y)^2']) for i in xrange(7): x = random.uniform(0, 10) y = random.uniform(0, 10) table.append([x, y, x-y, (x-y)**2]) table HTML """""") #Oops!!! from IPython.display import HTML HTML("""""") %matplotlib inline import numpy as np from pylab import * from matplotlib import pyplot as plt n = np.random.randn(100000) fig, axes = plt.subplots(1, 2, figsize=(12,4)) axes[0].hist(n) axes[0].set_title("Default histogram") axes[0].set_xlim((min(n), max(n))) axes[1].hist(n, cumulative=True, bins=50) axes[1].set_title("Cumulative detailed histogram") axes[1].set_xlim((min(n), max(n))); %matplotlib inline from matplotlib import pyplot as plt import numpy as np plt.plot(np.random.rand(100)) fig = plt.gcf() from pylab import * from matplotlib.patches import Polygon def func(x): return (x-3)*(x-5)*(x-7)+85 ax = subplot(111) a, b = 2, 9 # integral area x = arange(0, 10, 0.01) y = func(x) plot(x, y, linewidth=1) # make the shaded region ix = arange(a, b, 0.01) iy = func(ix) verts = [(a,0)] + list(zip(ix,iy)) + [(b,0)] poly = Polygon(verts, facecolor='0.8', edgecolor='k') ax.add_patch(poly) text(0.5 * (a + b), 30, r"$\int_a^b f(x)\mathrm{d}x$", horizontalalignment='center', fontsize=20) axis([0,10, 0, 180]) figtext(0.9, 0.05, 'x') figtext(0.1, 0.9, 'y') ax.set_xticks((a,b)) ax.set_xticklabels(('a','b')) ax.set_yticks([]) show()