Mean, Var, and Std

Sort by

recency

|

449 Discussions

|

  • + 0 comments
    import numpy
    
    n=list(map(int,input().split()))
    list1=[]
    for _ in range(n[0]):
        list1.append(list(map(int,input().split())))
    my_array = numpy.array(list1)
    print(numpy.mean(my_array, axis = 1))
    print(numpy.var(my_array, axis = 0))
    print(round(numpy.std(my_array, axis = None),11))
    
  • + 0 comments
    import numpy
    
    n, m = map(int, input().split())
    
    arr = numpy.array([list(map(int, input().split())) for _ in range(n)])
    
    print(numpy.mean(arr, axis=1))
    print(numpy.var(arr, axis=0))
    print(round(numpy.std(arr, axis=None),11))
    
  • + 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