# -*- coding: utf-8 -*-
"""
Created on Fri Nov 12 13:11:43 2021

@author: Sim
"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

height = np.array([167, 162, 158, 165, 160, 162, 162, 167, 156, 157])
weight = np.array([68, 49, 50, 56, 52, 52, 50, 61, 44, 55])

plt.plot(height, weight, 'b.')

cov1 = np.cov(height, weight, ddof=1)
print('cov1: ',cov1)

sxy = np.sum(height*weight)
mx = np.mean(height)
my = np.mean(weight)
n = len(weight)
cov2 = (sxy - n* mx * my) / (n-1)
print('cov2: ', cov2)

df = pd.DataFrame(data=np.column_stack([height,weight]))
cov3 = np.cov(df, ddof=1, rowvar=False)
print('cov3: ', cov3)
