- 1
Hi! DS with Python, first end of module project: means of rows: what's the problem with my code? It's ok in 3/5 testcases.
n, p = [int(x) for x in input().split()] X=[] i=0 while i<n: X.append(input()) i=i+1 v=0 while v<n: X[v]=X[v].split(" ") v=v+1 import numpy as np X_array=np.array(X) X_arrayf=X_array.astype(np.float) result=(X_arrayf.mean(axis=1)) np.around(result, decimals=2) print(result)
5 Antworten
0
for i in range(n):
X.append(input().split())
use for loop instead of two while
0
Thanks. So more elegant, but still doesn't work for the last 2 testcases.
0
import numpy as np
n, p = [int(x) for x in input().split()]
list = []
for i in range(n):
list.append(input().split())
arr = np.array(list).astype(np.float16).mean(axis=1).round(2)
print(arr)
np.float16 you instead of np.float
0
# i'd rather prefer to compute row means by my own, rather than using numpy methods:
import numpy as np
n, p = [int(x) for x in input().split()]
res = []
for i in range(n):
res.append(sum(
float(x) for x in input().split()
)/p)
print(np.array(res).round(2))
0
Thank you guys. Finally I realised, that I had the mistake only in the rounding row. Correctly: w=result.round(2)
print(w)
Now, it works. :)