Mean, Var, and Std

Sort by

recency

|

462 Discussions

|

  • + 0 comments

    For Python3 Platform

    It is not mentioned to round the value of standard deviation to 11 digits. I did it just to match the answer

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

    My compact solution…

    import sys
    import numpy as np
    
    print((a := np.loadtxt(sys.stdin.readlines()[1:], int)).mean(axis=1),
        a.var(axis=0), a.std().round(11), sep='\n')
    

    It's really very annoying that the results HackerRank expects is based on output using an old version of NumPy. After quickly solving the problem, it takes extra time to adjust it to appear the way they like it.