This notebook shows off some fun features. It was the notebook I played around with in the demo video online. video
In [1]:
2+2
Out[1]:
In [3]:
2**128
Out[3]:
In [5]:
def factorial(n):
r = 1
for i in range(n):
r *= i + 1
return r
factorial(3.5)
In [7]:
print("Hello, I am a pineapple")
In [9]:
from time import sleep
for i in range(5):
print("Hello, I am a pineapple")
sleep(0.5)
In [2]:
import numpy as np
M = np.array(range(13))
N = M.reshape(13,1)
M * N
Out[2]:
In [11]:
%timeit np.dot(M * N, M * N)
In [3]:
%matplotlib inline
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 100)
y = np.cos(x + np.cos(x))
plt.plot(x, y);
In [6]:
import urllib.request
import io
png = io.BytesIO(
urllib.request.urlopen('http://i.imgur.com/IyUsYQ8.png').read())
img = plt.imread(png)
img.shape
Out[6]:
In [7]:
plt.imshow(img[:, :, 0]);
In [18]:
import matplotlib
from scipy.cluster.vq import *
M = img[:,:,0].ravel()
centroids, _ = kmeans(M, 4)
q, _ = vq(M, centroids)
result = centroids[np.reshape(q, (400, 400))]
cmap = matplotlib.colors.ListedColormap([
(0,.2,.3), (.85,.1,.13), (.44,.6,.6), (1.,.9,.65)])
plt.imshow(result, cmap=cmap);
In [22]:
from ggplot import *
ggplot(meat, aes('date', 'beef')) + geom_line() + stat_smooth(span=0.3, color='red')
Out[22]:
In [23]:
from ivisual import *
scene = canvas()
sphere()
visual.display(scene)
In [26]:
from ivisual import *
scene = canvas('ball')
N = 60
balls = [sphere(color=color.red) for i in range(N)]
visual.display(scene)
t = 0.0
R = 3.0
while t < 20:
rate(60)
for i in range(N):
a = float(i) / N * 2 * np.pi
balls[i].pos = vector(R * np.sin(3*a + t), R * np.cos(5.0*a + t),
R * np.sin(2.0 * a + t))
t += 0.01
In [ ]:
# That's all folks