0
Not passing all the test cases
I was doing the exercise for the course "Data Science" named "Average of Rows". I am able to pass the first three test cases, but I am not able to pass the last two of them. Here is the code for that: import numpy as np n, p = [int(x) for x in input().split()] list_ = [] for i in range(n): a = input().split() sum_ = 0 for i in a: sum_ += float(i) ans = sum_/len(a) list_.append(ans) list_ = np.array(list_) print(list_) please help me debug the answer.
3 Respuestas
+ 1
Your second loop when u storing data in a . I think a should be list type becz at a time u can store one value . Length of (a) what it will print last value of a which can be a any values suppose your last entered values is 5 so a will be 5 . i dont have much more idea of python
+ 1
It's much easier to use numpy to get the mean values, and then also use numpy.around to round the hole list to two decimals. I suggest you take a look at W3Schools to find out how to do that.
0
Your trick worked. I rounded off using numpy array and passed all the test cases. But I was just wondering, if I rounded of the same list using round(number, decimals) I got wrong answer in the last test case.
Does numpy.round_(number, decimals) and simple round(number, decimals) works differently ??