+ 1

[solved] Data Science - Average of rows

Hey guys. I tried the Data Science Course and get stuck at the first Quiz/Task. Task Given a 2D array, return the rowmeans. Input Format First line: two integers separated by spaces, the first indicates the rows of matrix X (n) and the second indicates the columns of X (p) Next n lines: values of the row in X Output Format An numpy 1d array of values rounded to the second decimal. So i tried this but the hidden test cases 4 and 5 failed. Any idea whats wrong with my code? n, p = [int(x) for x in input().split()] #Werte aufnehmen spalte1=[] spalte2=[] for i in range(n): line=input().split() spalte1.append(float(line[0])) spalte2.append(float(line[1])) #numpy arrays erstellen import numpy as np nspalte1=np.array(spalte1) nspalte2=np.array(spalte2) nspalte1=nspalte1.reshape(-1,1) nspalte2=nspalte2.reshape(-1,1) #verbinden der arrays ganze_liste=np.concatenate((nspalte1,nspalte2),axis=1) #auswerten auswertung=ganze_liste.mean(axis =1) print(auswertung)

17th May 2022, 3:14 PM
Stefan
Stefan - avatar
8 Respuestas
+ 2
Yes. Try rounding results now..
18th May 2022, 11:18 AM
Jayakrishna 🇮🇳
+ 1
You're allowing only two columns. But the number of columns is not fixed.
17th May 2022, 3:26 PM
Simon Sauter
Simon Sauter - avatar
+ 1
Hint: in the for loop create the rows, not the columns.
17th May 2022, 3:30 PM
Simon Sauter
Simon Sauter - avatar
+ 1
Jayakrishna🇮🇳 this I was also thinking about but some of the results I could see were also not rounded and they are perfect (and the solution was also not rounded) so I think this is not the point Simon Sauter this I will try
17th May 2022, 3:33 PM
Stefan
Stefan - avatar
+ 1
I did change the code like this but still the hidden test cases 4 and 5 fail. n, p = [int(x) for x in input().split()] #Werte aufnehmen arr=[] for i in range(n): line=input().split() arr.append(list(map(float,line))) #numpy arrays erstellen import numpy as np values=np.array(arr) #auswerten print(values.mean(axis =1))
17th May 2022, 3:56 PM
Stefan
Stefan - avatar
+ 1
Round the results to two decimals and it passes.
17th May 2022, 4:54 PM
Simon Sauter
Simon Sauter - avatar
+ 1
So I finally had the time to test your suggestion Simon Sauter Jayakrishna🇮🇳 and it worked. So thank your for your help guys :)
19th May 2022, 1:33 PM
Stefan
Stefan - avatar
0
After reading task, I think you missing the "rounded to the 2 decimals"?
17th May 2022, 3:29 PM
Jayakrishna 🇮🇳