Skip to content

Instantly share code, notes, and snippets.

@ostwalprasad
Created March 20, 2020 09:55
Show Gist options
  • Save ostwalprasad/f4f3de7d9bdae087b3b5cefb74110e23 to your computer and use it in GitHub Desktop.
Save ostwalprasad/f4f3de7d9bdae087b3b5cefb74110e23 to your computer and use it in GitHub Desktop.
Covariance matrix only using NumPy
import numpy as np
import pandas as pd
df = YOUR_DATAFRAME
ones = np.ones([df_shape[0],df_shape[0]])
dev_mat = df - (ones @ df)/df_shape[0]
cov_mat = (dev_mat.T @ dev_mat) / df_shape[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment