0
Average of rows end of module project from data science course
from the test cases 4 out of 5 are correct. But can't make the last one correct. I suspect the problem is with the round function. Can anyone help me with my code? https://code.sololearn.com/calpruBFk5FV/?ref=app
4 Réponses
+ 1
I think that is because rounding in NumPy is different from rounding in Python.
So use numpy.round() method instead of Python round function:
Append first each rows to 'b' (not rounded) then use numpy round method at last line to round off each value.
_______________________
import numpy as np
n, p = [int(x) for x in input().split()]
b = np.array([])
for i in range(n):
a = list(float(i) for i in input().split())
b = np.append(b,sum(a)/len(a))
print(b.round(2))
________________________
+ 1
n, p = [int(x) for x in input().split()]
list = []
for i in range(n):
list.append([float(j) for j in input().split()])
import numpy as np
arr = np.array(list, dtype='f')
mean = arr.mean(axis=1)
print(mean.round(2))
+ 1
Copy this code and like and check
0
Thanks a lot Cyan . It worked ❤️