Skip to content

Instantly share code, notes, and snippets.

@pharpend
Created November 22, 2017 19:48
Show Gist options
  • Save pharpend/abcda43b6e8dbfdbf11438bdada66bb8 to your computer and use it in GitHub Desktop.
Save pharpend/abcda43b6e8dbfdbf11438bdada66bb8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import division
import numpy as np
f = open('clean1.data', 'r')
f_nums = [map(float, x.strip().split(',')[2:]) for x in f.readlines()]
d = np.array(f_nums)
d_cols = d.transpose()
means = [np.mean(col) for col in d_cols]
d_mean_centered = []
for row in d.tolist():
mean_centered_row = []
for (ety, mu) in zip(row, means):
mean_centered_row.append(ety - mu)
d_mean_centered.append(mean_centered_row)
d = np.matrix(d)
d_mean_centered = np.matrix(d_mean_centered)
c = d_mean_centered.transpose() * d_mean_centered #* (1/d.shape[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment