In [14]:
from IPython.display import Image

In [15]:
Image('pang_prof.png', width=1000)


Out[15]:

In [16]:
Image('mi_prof.png', width=400)


Out[16]:

Vectorized Numpy Operations Avoid Excessive Bounds-Checking


In [20]:
import numpy as np

a = np.random.rand(10**7)
b = np.random.rand(10**7)
c = np.zeros(10**7)

def example1():
    c=a+b
    
def example2():
    for i in xrange(len(a)):
        c[i] = a[i] + b[i]

def example3():
    tmp = 0
    for i in xrange(len(a)):
        tmp += 1

In [21]:
%timeit -r 1 example1()


10 loops, best of 1: 36.9 ms per loop

In [22]:
%timeit -r 1 example2()


1 loop, best of 1: 3.68 s per loop

In [23]:
%timeit -r 1 example3()


1 loop, best of 1: 490 ms per loop

Finite Precision Breaks Commutivity

$\pm\Big(\sum_{i=0}^{p-1} a_i \beta^{-i} \Big)\beta^e$


In [37]:
from math import pi
x = (pi + 10**17) - 10**17
print np.cos(x)
print np.cos(pi)


1.0
-1.0

In [33]:
from math import pi
rad = 2 * pi
x = (rad / pi) * 180 * 60
y = (rad * 180 * 60) / pi
print np.cos(x)
print np.cos(y)


-0.0202883645238
-0.0202883645201