Calculating Covariance with Python and Numpy
When a and b are 1-dimensional sequences, numpy.cov(a,b)[0][1] is equivalent to your cov(a,b). The 2×2 array returned by np.cov(a,b) has elements equal to (where, again, cov is the function you defined above.)