• + 0 comments

    I am bit confused why its not mentioned to take the population standard deviation instead of the sample standarddeviation

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    import math
    import statistics
    n = int(input())
    
    
    X =list(map(float, input().split()))
    
    
    Y =list(map(float, input().split()))
        
    
    def calcpearsonCov(dataset1, dataset2):
        averagex= statistics.mean(dataset1)
        averagey = statistics.mean(dataset2)
        result = 0
        for i in range(0, len(dataset1)):
            result += (dataset1[i] - averagex) * (dataset2[i]- averagey)
        #result = result *(1/len(dataset1))
        stdevx = statistics.pstdev(dataset1)
        stdevy = statistics.pstdev(dataset2)
        result = result/(n*(stdevx*stdevy))
        return result
        
    result = calcpearsonCov(X, Y)
    print(round(result, 3))