Completely free Python distribution for large-scale data processing, predictive analytics, and scientific computing:
Miniconda available for small footprint installs -- contains conda and Python
Download at http://continuum.io
The official conda repository contains 200+ pkgs
$ bash Anaconda-1.x.x-Linux-x86[_64].sh
click on downloaded dmg/exe and follow instructions
Anaconda installs in a single directory and does not overwrite pre-existing Python environments.
With anaconda installed you are now ready to tackle the problem at hand...
Launch an ipython notebook
$ ipython notebook
#or
C:/>ipython notebook
Anaconda is really just a meta-package of pre-defined libraries, modules, and binaries
Conda is a cross-platform, Python-agnostic binary package manager.
Again, Conda is cross-platform.
Anaconda with Python 3.3
$ conda create -n py3k python=3.3 anaconda=1.9
$ source activate py3k
#on windows
C:> activate py3k
Minimalist Environment
$ conda create -n tinyp27 python=2.7
$ source activate tinyp27
#on windows
C:> activate tinyp27
"The IPython Notebook is a web-based interactive computational environment where you can combine code execution, text, mathematics, plots and rich media into a single document"
Extremely Easy Method:
$ipython or $ipython notebook
Can also be installed via pip
and building from master
1+1
2
%pylab inline
#(import numpy as np and matplotlib)
plt.xkcd()
x = np.arange(0,2*np.pi,.01)
plt.plot(x,np.sin(x))
Populating the interactive namespace from numpy and matplotlib
[<matplotlib.lines.Line2D at 0x1092dd410>]
Execute a cell with:
from IPython.display import HTML
s = """<marquee>PyData EMC</marquee>"""
h = HTML(s); h
%%HTML
<button type="button" id="loading-example-btn" data-loading-text="Loading..." class="btn btn-primary">
Loading state
</button>
%%javascript
console.log('hello world');
<IPython.core.display.Javascript at 0x105f51810>
import bokeh.plotting as bplt
bplt.output_notebook()
bplt.figure()
bplt.line(x, sin(x), color="red")
bplt.show()
Configuring embedded BokehJS mode.
from IPython.display import HTML
HTML('<iframe src=http://fiddle.jshell.net/bokeh/K8P4P/show/ width=600 height=700></iframe>')
import numpy as np
from IPython.display import Audio
framerate = 44100
t = np.linspace(0,5,framerate*5)
data = np.sin(2*np.pi*220*t**2)
Audio(data,rate=framerate)
from IPython.display import YouTubeVideo
YouTubeVideo('xe_ATRmw0KM')
%%latex \begin{align} \frac{\partial u}{\partial t} + \nabla \cdot \left( \boldsymbol{v} u - D\nabla u \right) = f \end{align}
from IPython.display import Latex
from IPython.display import Math
- %lsmagic
- %timeit/%%timeit
- %%file
- %%bash
- %%cythonmagic
%timeit np.linalg.eigvals(np.random.rand(100,100))
100 loops, best of 3: 11.2 ms per loop
%%timeit
a = np.random.rand(100, 100)
np.linalg.eigvals(a)
100 loops, best of 3: 11 ms per loop
%%bash
echo "HELLO WORLD!"
HELLO WORLD!
%%file zenofpython.py
'''this is a brand new file'''
import this
Overwriting zenofpython.py
import zenofpython
The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!
%load_ext cythonmagic
%%cython --annotate
def slow_f(n):
x = 100.
for i in range(n):
x+=n
return x
def fast_f(int n):
cdef double x=100.
cdef int i
for i in range(n):
x+=n
return x
Generated by Cython 0.19.1 on Fri Feb 7 22:22:24 2014
1: def slow_f(n):
2: x = 100.
3: for i in range(n):
4: x+=n
5: return x
6:
7: def fast_f(int n):
8: cdef double x=100.
9: cdef int i
10: for i in range(n):
11: x+=n
12: return x
I've heard Bang or Shriek --> !
!ls
CGM_DEMO.ipynb LICENSE myfile.txt IPythonOverview.ipynb README.md zenofpython.py IPythonOverview.slides.html ca_website.png zenofpython.pyc
!cat CGM_DEMO.ipynb | sort | uniq -c | sort -r | head
41 { 41 "metadata": {}, 40 }, 21 ] 21 "source": [ 21 "cell_type": "markdown", 20 ], 20 "outputs": [] 20 "language": "python", 20 "input": [
%%ruby
puts "Hello from Ruby #{RUBY_VERSION}"
Hello from Ruby 1.8.7
%load_ext rmagic
##requires rpy2 and rtools and R
X = np.array([0,1,2,3,4])
Y = np.array([3,5,4,6,7])
%%R -i X,Y -o XYcoef;
XYlm = lm(Y~X);
XYcoef = coef(XYlm);
#print(summary(XYlm))
par(mfrow=c(2,2))
plot(XYlm)
HTML('<iframe src=http://nbviewer.ipython.org/github/creswick/ihaskell-notebook/blob/master/examples/iHaskell%20Examples.ipynb width=1024 height = 500></iframe>')
Not MapReduce (Data should remain static)
Starts With: $ipcluster start -n 4
from IPython.parallel import Client
c = Client()
c.ids
[0, 1, 2, 3]
c[:].apply_sync(lambda : "Hello, World")
['Hello, World', 'Hello, World', 'Hello, World', 'Hello, World']
IPython Team:
Damián Avila authored the Reveal.js nbconvert utility
$ipython nbconvert IPythonOverview.ipynb --to slides
$ipython nbconvert IPythonOverview.ipynb --to slides --post serve
Rethinking how data is stored, computed, and visualized.
from IPython.display import Image
Image(filename='ca_website.png',width=800,height=700)