Standard deviation of a list

后端 未结 8 1741
旧时难觅i
旧时难觅i 2020-12-07 09:57

I want to find mean and standard deviation of 1st, 2nd,... digits of several (Z) lists. For example, I have

A_rank=[0.8,0.4,1.2,3.7,2.6,5.8]
B_rank=[0.1,2.8,         


        
8条回答
  •  感动是毒
    2020-12-07 10:09

    Using python, here are few methods:

    import statistics as st
    
    n = int(input())
    data = list(map(int, input().split()))
    

    Approach1 - using a function

    stdev = st.pstdev(data)
    

    Approach2: calculate variance and take square root of it

    variance = st.pvariance(data)
    devia = math.sqrt(variance)
    

    Approach3: using basic math

    mean = sum(data)/n
    variance = sum([((x - mean) ** 2) for x in X]) / n
    stddev = variance ** 0.5
    
    print("{0:0.1f}".format(stddev))
    

    Note:

    • variance calculates variance of sample population
    • pvariance calculates variance of entire population
    • similar differences between stdev and pstdev

提交回复
热议问题