0

Data Science - Average of Rows

hello, i am trying to solve the code challenge at the end of chapter1 of the data science course and i can only pass 3 out of 5 tests and i can't figure out why my code is not working in all the cases #input of the first line containg the size of rows(n) and columns(p) of a data set n, p = [int(x) for x in input().split()] my first approach was to read the next lines containg the data for the data set and add them into a list and transform that into a ndarray import numpy as np myList = [] for index in range(n): p1 = [float(x) for x in input().split()] p1=[float("{:.2f}".format(i)) for i in p1] myList.append(p1) myArr = np.array(myList) myArr.reshape(n,p) print(myArr.sum(axis=1)/p) with this method i convert the string value in a float one and then impose a 2 digits float number format. i then sum by row and display the average can someone help me understand where i might not see a bug in my flow?

23rd Apr 2022, 7:56 AM
Gabriel Bigioi
Gabriel Bigioi - avatar
6 Antworten
+ 2
Remove line 38 – do not round the input values. Calculte the mean simy by using the .mean() method. Round the result by 2 places, using the .round(2) method
23rd Apr 2022, 8:44 AM
Lisa
Lisa - avatar
+ 1
That is exactly what "put your code in a script on sololearn playground" means ;)
23rd Apr 2022, 8:40 AM
Lisa
Lisa - avatar
+ 1
Great that you solved the issue!
23rd Apr 2022, 8:49 AM
Lisa
Lisa - avatar
0
Please put your code in a script on sololearn playground instead of copying it into the description. Go to Code section, click +, select Python, insert code. Come back to this thread, click +, Insert Code, sort for My Code Bits, select your code.
23rd Apr 2022, 8:17 AM
Lisa
Lisa - avatar
0
https://code.sololearn.com/c2LTVbM9Gq78/#py i could not perform the "click +, Insert Code, sort for My Code Bits, select your code" because i can't find the + button, but i posted my code on the playground and here is the link.
23rd Apr 2022, 8:38 AM
Gabriel Bigioi
Gabriel Bigioi - avatar
0
It worked, thanks! I tried using mean but I thought that the problem must have been in the rounding but could not work around that issue. Thank you a lot
23rd Apr 2022, 8:47 AM
Gabriel Bigioi
Gabriel Bigioi - avatar