Skip to content

Instantly share code, notes, and snippets.

View andim's full-sized avatar

Andreas Tiffeau-Mayer andim

View GitHub Profile
@andim
andim / lstsqr.py
Created June 10, 2014 00:25
Comment on @rasbt's benchmark
def python_lstsqr(x, y):
""" Computes the least-squares solution to a linear matrix equation. """
len_x = len(x)
x_avg = sum(x)/len_x
y_avg = sum(y)/len(y)
var_x = 0
cov_xy = 0
var_x = np.sum((x - x_avg)**2)
cov_xy = np.sum((x - x_avg)*(y - y_avg))
slope = cov_xy / var_x