Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 11
Data Science - Average of Rows. Has anybody solved this Code Coach Challengeāļø - SOLVED
My code doesn't pass the last, #5ļøā£ testā¼ļø Any ideasāļøš¤
19 Respostas
+ 9
My code:
n, p = [int(x) for x in input().split()]
rm = [] # rowmean
[rm.append(round(sum([float(i) for i in input().split()])/p, 2)) for j in range(n)]
import numpy as np
print(np.array(rm))
Outputs: test case #5ļøā£
my: [1.95 2.23 2.67 1.62]
#5ļøā£: [1.95 2.22 2.68 1.62]
difference: +0.01 -0.01
Probably the problem is in number rounding āļøš¤
my: round(x,2)
other: x.round(2)
Sorryā¼ļøI can't show in public the code which has passed all 5ļøā£ testsā¼ļøā¹ļø
+ 6
I have used np.around and it worked!
https://docs.scipy.org/doc/numpy/reference/generated/numpy.around.html
+ 5
"For values exactly halfway between rounded decimal values, NumPy rounds to the nearest even value. Thus 1.5 and 2.5 round to 2.0, -0.5 and 0.5 round to 0.0, etc.Ā ... "
Notes from: docs.scipy.org/doc
+ 4
Interesting š¤ but in this code coach that's not going to happen because we are rounding to 2 decimal places not to an int value we don't need that method.
Janusz Bujak šµš±
I was on the right track. Problem wasn't the round functionality at all but the way you calculated the mean. Replace your sum()/p logic with nparray.mean() and your code will work even when you used the round(x,2) form.
+ 3
Janusz Bujak šµš± You are right. I misunderstood that sorry.
+ 3
Which challenge you are talking about, guys? Can you send a link?
+ 3
Kuba SiekierzyÅski
https://www.sololearn.com/coach/111?ref=app
Data Science - Average of Rows
+ 3
DziÄki, Janusz Bujak šµš± , I couldn't find it on the code coach list... š¤
+ 3
Kuba SiekierzyÅski You must advance in your course and the challenge will be available as a DM from SL.
+ 3
BEN_10š®š³
Besides the 72 CCC accessible from the Learn tab, there are 10 more CCC (Python only) related to Data Science and Machine Learning courses which will be available as DM from SL as you advance through the mentioned courses.
+ 3
Erik Gordon-Quaicoe
Amir Mehrabi Jorshari
import numpy as np
n, p = [int(x) for x in input().split()]
m = []
[m.append([float(i) for i in input().split()]) for j in range(n)]
print(np.mean(np.array(m), axis=1).round(2))
+ 2
No idea. I already solved it so you can DM me because its Pro.
+ 2
I don't know. This looks like another rounding issue. I used the numpy array mean and round functions and it works.
Right now I don't know if the problem is rounding or the division operator.
+ 2
Kevin Star
Sorry but this note applies to all rounding levels:
https://code.sololearn.com/cSmkN8fGY6dG/?ref=app
Thanks for your advice but I've already solved this CCChallengeā¼ļøš
+ 1
can anyone help me with test case #1 at least to get the concept so that i can research the rest on my own. Iām really stuck. please
+ 1
Erik Gordon-Quaicoe Read the PROBLEM again & all A in this Q&Aā¼ļø Pay close attention to problems with round(), read about numpy mean & show me your codeā¼ļøš
+ 1
Janusz Bujak šµš± import numpy as np
ls = []
for i in range (2):
ls.append(input().split())
ls_arr = np.array(ls)
rm = ls_arr.astype(float)
print (np.mean(rm, axis=1))
+ 1
the Numpy has already a round function.
n, p = [int(x) for x in input().split()]
import numpy as np
ls = []
for i in range (n):
ls.append(input().split())
ls_arr = np.array(ls)
rm = ls_arr.astype(float)
result = np.mean(rm, axis=1).round(2)
+ 1
Data Science - the perfect solution for average of rows
n, p = [int(x) for x in input().split()]
import numpy as np
rm = []
for i in range(n):
for a in input().split():
rm.append(float(a))
a = np.array(rm).reshape((n,p))
c = np.mean(a,axis=1)
p = np.around(c,2)
print(p)