from IPython.display import HTML %load_ext load_style %load_style talk.css HTML('') ### This is a code cell, containing python code, it is executed by - or - def func(x): return x**2 [func(x) for x in xrange(10)] some_dict = {} some_dict? from numpy import random random? help(random) # produces a long output below instead of in a dedicated frame. - listA = [1, 2., 'sentence', 1, (1,2), {'answer': 42}] # here I construct a LIST containing different items listA listA.count(1) listA.count(2.0) listA.count( listA from IPython.display import Image, YouTubeVideo ### that will display a frame with specified width and height ... HTML('') ### This inserts an image in the output cell Image(filename='images/lost_wormhole.jpg',width=500) ### This embeds a video from YouTube ### You can embed Vimeo videos by calling from IPython.display import VimeoVideo # Fernando PĂ©rez at PyConCA, here I start at 30 minutes YouTubeVideo('F4rFuIb1Ie4', start = 30*60) ### You can also embed a LOCAL video in the notebook, but have to encode it: Not sure it will work ### on Windows ... import io import base64 filename = './data/Astro_ML_PYDATA2012.mp4' video = io.open(filename, 'r+b').read() encoded = base64.b64encode(video) HTML(data=''''''.format(encoded.decode('ascii'))) import numpy as np import matplotlib.pyplot as plt # this is a magic IPython command (%) allowing matplotlib plots to be displayed inline in the notebook %matplotlib inline t = np.linspace(0, 2*np.pi, 100) plt.plot(np.sin(t)) # you can also choose to display figure OUTSIDE the notebook # the available backends are [inline|qt|osx|gtx] ... For Windows try qt %matplotlib osx t = np.linspace(0, 2*np.pi, 100) plt.plot(np.sin(t)) %matplotlib inline %lsmagic %whos %%file tmp.py #!/usr/bin/env python import numpy as np print('Hello world') a = np.arange(10) ### will be available in the namespace %run tmp.py a %load tmp.py #!/usr/bin/env python import numpy as np print('Hello world') a = np.arange(10) ### will be available in the namespace #!/usr/bin/env python import numpy as np print('Hello world') a = np.arange(10) ### will be available in the namespace ### loading an example from the matplotlib gallery %load http://matplotlib.org/mpl_examples/images_contours_and_fields/streamplot_demo_features.py """ Demo of the `streamplot` function. A streamplot, or streamline plot, is used to display 2D vector fields. This example shows a few features of the stream plot function: * Varying the color along a streamline. * Varying the density of streamlines. * Varying the line width along a stream line. """ import numpy as np import matplotlib.pyplot as plt Y, X = np.mgrid[-3:3:100j, -3:3:100j] U = -1 - X**2 + Y V = 1 + X - Y**2 speed = np.sqrt(U*U + V*V) plt.streamplot(X, Y, U, V, color=U, linewidth=2, cmap=plt.cm.autumn) plt.colorbar() f, (ax1, ax2) = plt.subplots(ncols=2) ax1.streamplot(X, Y, U, V, density=[0.5, 1]) lw = 5*speed/speed.max() ax2.streamplot(X, Y, U, V, density=0.6, color='k', linewidth=lw) plt.show() !rm tmp.py ### ! escapes to the OS (!del tmp.py on windows) notebooks = !ls ?_*.ipynb ### notebooks is a python list ... not sure how to use wildcards on Windows notebooks %%bash # Substitutes underscores for blanks in all the filenames in a directory. ONE=1 # For getting singular/plural right (see below). number=0 # Keeps track of how many files actually renamed. FOUND=0 # Successful return value. for filename in * # Traverses all files in directory. do echo "$filename" | grep -q " " # Checks whether filename if [ $? -eq $FOUND ] # contains space(s). then fname=$filename # Strips off path. n=`echo $fname | sed -e "s/ /_/g"` # Substitutes underscore for blank. mv "$fname" "$n" # Do the actual renaming. let "number += 1" fi done if [ "$number" -eq "$ONE" ] # For correct grammar. then echo "$number file renamed." else echo "$number files renamed." fi exit 0 #!ipython nbconvert --help !/Users/nicolasfauchereau/anaconda/bin/ipython nbconvert --help # needs pandoc installed (http://johnmacfarlane.net/pandoc/installing.html) #! ipython nbconvert 1_Overview_IPython.ipynb --to html !/Users/nicolasfauchereau/anaconda/bin/ipython nbconvert 1_Overview_IPython.ipynb --to html %quickref