 [solved] Data Science - Average of rows | Sololearn: Learn to code for FREE!

+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)) spalte2.append(float(line)) #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)

+2

So I finally had the time to test your suggestion Simon Sauter Jayakrishna🇮🇳 and it worked. So thank your for your help guys :)

+1

You're allowing only two columns. But the number of columns is not fixed.

+1

Hint: in the for loop create the rows, not the columns.

+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

+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))

+1

Round the results to two decimals and it passes.

+1

Yes. Try rounding results now..

0

After reading task, I think you missing the "rounded to the 2 decimals"?