$ which ipython /Users/ivan/dev/anaconda/bin/ipython $ cd ~/dev/proj/pyconsg2013-tut/ipynb $ pwd /Users/ivan/dev/proj/pyconsg2013-tut/ipynb $ ipython notebook [NotebookApp] Using existing profile dir: u'/Users/ivan/.ipython/profile_default' [NotebookApp] Serving notebooks from /Users/ivan/dev/proj/pyconsg2013-tut/ipynb [NotebookApp] The IPython Notebook is running at: http://127.0.0.1:8888/ [NotebookApp] Use Control-C to stop this server and shut down all kernels. [NotebookApp] Using MathJax from CDN: http://cdn.mathjax.org/mathjax/latest/MathJax.js [NotebookApp] Kernel started: 8843b5b0-be77-4b41-9e90-ed5af6bafbbb [NotebookApp] Connecting to: tcp://127.0.0.1:52020 [IPKernelApp] To connect another client to this kernel, use: [IPKernelApp] --existing kernel-8843b5b0-be77-4b41-9e90-ed5af6bafbbb.json [NotebookApp] Connecting to: tcp://127.0.0.1:52021 [NotebookApp] Connecting to: tcp://127.0.0.1:52023
Git:
$ git clone https://github.com/vanzaj/pyconsg2013-tut.git
or download from https://github.com/vanzaj/pyconsg2013-tut/archive/master.zip
Consider a circle inside a square
$$ \frac{A_{circle}}{A_{square}} = \frac{\pi r^2}{(2r)^2} = \frac{\pi}{4} $$The value of $\pi$ can be found from the ratio of the areas times 4. If we don't know the areas, we can still estimate the ratio by considering a set of random points inside the square and the fraction of points inside the circle (thinks (a few) games of darts).
%pylab inline
Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline]. For more information, type 'help(pylab)'.
nb_pts = 5000
px = rand(nb_pts) # x coordinates
py = rand(nb_pts) # y coordiantes
inside = find((px**2 + py**2) <= 1.0)
nb_inside = len(inside)
ratio = float(nb_inside)/nb_pts
print("pi estimate: %5.3f" % (ratio * 4))
pi estimate: 3.170
axis('scaled')
plot(px, py, '.')
plot(px[inside], py[inside], 'r.')
# quarter of a circle
cx = linspace(0,1, 100)
cy = sqrt(1 - cx**2)
plot(cx, cy, 'k-', linewidth=2)
[<matplotlib.lines.Line2D at 0x10633fe90>]
(Sorry, forgot to mention BigData above)
Core functionality
(pylab
is a helper package created to facilitate interactive work inside ipython
. It allows importing everything from numpy
and matplotlib
into the current namespace).
Main packages/libraries
Specialized packages/libraries
Distributions/Development environments
import sys, IPython, numpy, matplotlib
print 'Python %d.%d.%d' % (sys.version_info.major, sys.version_info.minor, sys.version_info.micro)
print 'Ipython', IPython.__version__
print 'NumPy', numpy.version.version
print 'MPL', matplotlib.__version__
Python 2.7.4 Ipython 0.13.2 NumPy 1.7.1 MPL 1.2.1