def pearson_score(list1, list2):
 size = len(list1)
 sum1 = sum(list1)
 sum2 = sum(list2)
 sum_sq1 = sum([pow(l, 2) for l in list1])
 sum_sq2 = sum([pow(l, 2) for l in list2])
 prod_sum = sum([(list1[i] * list2[i]) for i in range(size)])
 num = (prod_sum - ((sum1 * sum2) / float(size)))
 den = sqrt(((sum_sq1 - (pow(sum1, 2.0) / size)) * (sum_sq2 - (pow(sum2, 2.0) / size))))
 return (num / den)

def pearson_score ( list1 , list2 ) : size = len ( list1 ) sum1 = sum ( list1 ) sum2 = sum ( list2 ) sum_sq1 = sum ( [ pow ( l , 2 ) for l in list1 ] ) sum_sq2 = sum ( [ pow ( l , 2 ) for l in list2 ] ) prod_sum = sum ( [ ( list1 [ i ] * list2 [ i ] ) for i in range ( size ) ] ) num = ( prod_sum - ( ( sum1 * sum2 ) / float ( size ) ) ) den = sqrt ( ( ( sum_sq1 - ( pow ( sum1 , 2.0 ) / size ) ) * ( sum_sq2 - ( pow ( sum2 , 2.0 ) / size ) ) ) ) return ( num / den )
compute the pearson score between 2 lists of vectors .