Mean, Var, and Std

Sort by

recency

|

447 Discussions

|

  • + 0 comments

    import numpy as np

    i = input()

    n,m = list(map(int,i.split(' ')))

    arr = np.array([list(map(int,input().split(' '))) for _ in range(n)])

    print(np.mean(arr,axis=1)) print(np.var(arr,axis=0)) print(np.round(np.std(arr,axis=None),11))

  • + 0 comments

    For Python3 Platform

    It isn't mentioned to round off the standard deviation to 11 decimals. I did that just to match with the given answer.

    from numpy import array, mean, var, std
    
    arr = []
    n, m = map(int, input().split())
    
    for _ in range(n):
        arr.append([*map(int, input().split())])
    arr = array(arr)
    
    print(mean(arr, axis=1))
    print(var(arr, axis=0))
    print(round(std(arr), 11))
    
  • + 1 comment

    I did two things to make it work for all the test cases:

    1) commented out printoptions that were recommended in the previous examples, but were not needed in this question

    2) added rounding to 11th decimal place to calculate std: print(numpy.round(numpy.std(arr, axis = None),11))

    Hope thois helps

    • + 0 comments

      Thanks Edvard

  • + 0 comments

    import numpy as np

    i, j = map(int, input().split())

    arr = np.array([list(map(int, input().split())) for _ in range(i)])

    print(np.mean(arr, axis=1)) print(np.var(arr, axis=0))

    std_value = np.std(arr, axis=None) if std_value == 0: print("0.0") else: print(f"{std_value:.11f}")

  • + 0 comments
    import numpy as np
    
    n,m=map(int, input().split())
    l=[]
    for _ in range(n):
      l.append(list(map(int, input().split())))
    ar=np.array(l)
    print(np.mean((ar),axis=1))
    print(np.var((ar),axis=0))
    print(round(np.std(ar),11))