We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Numpy
- Mean, Var, and Std
- Discussions
Mean, Var, and Std
Mean, Var, and Std
Sort by
recency
|
447 Discussions
|
Please Login in order to post a comment
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))
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.
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
Thanks Edvard
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}")