In [47]:
import timeit

point_counter = [10, 1e2, 1e3, 1e4, 1e5]
unvec_times = []
vec_times = []
for count in point_counter:
    setup_code = """import numpy as np
x = np.random.rand("""+str(count)+""", 10)
def energy(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10):
    return x1*np.log(x1) + x2*np.log(x2) + x3*np.log(x3) + x4*np.log(x4) + x5*np.log(x5) + x6*np.log(x6) + x7*np.log(x7) + x8*np.log(x8) + x9*np.log(x9) + x10*np.log(x10)
def unvectorized(x):
    output = np.empty(len(x))
    for idx, point in enumerate(x):
        output[idx] = energy(*point)
    return output
def vectorized(x):
    return energy(*x.T)"""
    unvec_times.append(min(timeit.Timer('unvectorized(x)', setup=setup_code).repeat(7, 3)))
    vec_times.append(min(timeit.Timer('vectorized(x)', setup=setup_code).repeat(7, 3)))

In [53]:
%matplotlib inline
import matplotlib.pyplot as plt
plt.figure(figsize=(10,6))
plt.plot(point_counter, unvec_times, color='red', label='unvectorized')
plt.plot(point_counter, vec_times, color='blue', label='vectorized')
plt.xlabel('Number of Points')
plt.ylabel('Time (sec)')
plt.xscale('log')
plt.yscale('log')
plt.legend(loc=2)
plt.show()



In [5]:
import scipy.linalg
import numpy as np

A = [[1], [1], [1]]
H = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
Q, R = scipy.linalg.qr(A, mode='full')
np.dot(np.dot(Q[:, :-1].T, H), Q[:, :-1]


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-47cecacb1db2> in <module>()
      5 H = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
      6 Q, R = scipy.linalg.qr(A, mode='full')
----> 7 Q[:, :-1].T . H . Q[:, :-1]

AttributeError: 'numpy.ndarray' object has no attribute 'H'

In [ ]: