Mean, Var, and Std

Sort by

recency

|

441 Discussions

|

  • + 0 comments
    import numpy as np 
    
    N,M = map(int, input().split())
    
    input_list = []
    
    for i in range(N):
        input_list.append(list(map(int, input().split())))
     
    np_input_list = np.array(input_list, dtype=int)   
    
    print(np.mean(np_input_list, axis = 1))
    print(np.var(np_input_list,  axis = 0))
    print(round(np.std(np_input_list),11))
    
  • + 0 comments

    Had to round numpy.std value off to the 11th decimal ( i know i'm not the first one to find that out ;) )

    import sys, re, numpy
    
    entry = sys.stdin.read().replace(' ', '').splitlines()[1:]
    
    my_array = []
    for line in entry:
        my_array.append([int(i) for i in re.findall(r"\d", line)])
        
    my_array = numpy.array(my_array)
    print(numpy.mean(my_array, axis=1), numpy.var(my_array, axis=0), round(numpy.std(my_array, axis=None), 11), sep='\n')
    
  • [deleted]Challenge Author
    + 0 comments

    For Python3

    It itsnt mentioned to round off the std value to 11 decimals. So, use round function just to match the answer.

    import numpy
    
    n, m = map(int, input().split())
    arr = numpy.array([input().split() for i in range(n)], dtype=int)
    
    print(numpy.mean(arr, axis=1))
    print(numpy.var(arr, axis=0))
    print(round(numpy.std(arr), 11))
    
  • + 0 comments

    import numpy N, M = map(int, input().strip().split()) my_arr = numpy.array([input().strip().split()[:M] for _ in range(N)], dtype=numpy.float_) print(numpy.mean(my_arr, axis=1)) print(numpy.var(my_arr, axis=0)) print(round(numpy.std(my_arr, axis = None), 11))

  • + 0 comments

    import numpy

    n , m = map(int,input().split())

    arrayList = [] for i in range(n): arrayList.append(list(map(int,input().split())))

    my_array = numpy.array(arrayList) print(numpy.mean(my_array, axis = 1)) print(numpy.var(my_array, axis = 0)) print(round(numpy.std(my_array, axis = None), 11))