I have two vectors, I am trying to use them in a function to return just the sample covariance.
Can anyone help me fix my program? I am new to python and programming in general.
xv= array([8., 9.5, 7.8, 4.2, -7.7, -5.4, 3.2])
yv= array([8.9, 2.0, 4.8, -4.2, 2.7, -3.4, -5.9])
def cov(x,y):
if (len(x) != len(y)
[Stop]
x.bar = mean(x)
y.bar = mean(y)
N = len(x)
Cov = (sum((x-x.bar)*(y-y.bar))) / (N-1.0)
return(Cov)
Here is my version without using external libraries. The equation for covariance is from Wikipedia: http://en.wikipedia.org/wiki/Covariance