+ 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⁉️🤔

3rd Apr 2020, 10:18 PM
Janusz Bujak 🇵🇱
Janusz Bujak 🇵🇱 - avatar
20 Answers
+ 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‼️☹️
4th Apr 2020, 9:00 AM
Janusz Bujak 🇵🇱
Janusz Bujak 🇵🇱 - avatar
6th Apr 2020, 3:23 PM
Isabela Poley
Isabela Poley - avatar
+ 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
6th Apr 2020, 3:44 PM
Janusz Bujak 🇵🇱
Janusz Bujak 🇵🇱 - avatar
+ 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.
6th Apr 2020, 5:12 PM
Kevin ★
+ 3
Janusz Bujak 🇵🇱 You are right. I misunderstood that sorry.
6th Apr 2020, 8:01 PM
Kevin ★
+ 3
Which challenge you are talking about, guys? Can you send a link?
13th Apr 2020, 8:23 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
13th Apr 2020, 8:36 AM
Janusz Bujak 🇵🇱
Janusz Bujak 🇵🇱 - avatar
+ 3
Dzięki, Janusz Bujak 🇵🇱 , I couldn't find it on the code coach list... 🤔
13th Apr 2020, 8:50 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 3
Kuba Siekierzyński You must advance in your course and the challenge will be available as a DM from SL.
13th Apr 2020, 1:55 PM
Mihai Apostol
Mihai Apostol - avatar
+ 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.
14th Apr 2020, 6:45 AM
Mihai Apostol
Mihai Apostol - avatar
+ 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))
20th Feb 2021, 11:59 PM
Janusz Bujak 🇵🇱
Janusz Bujak 🇵🇱 - avatar
+ 2
No idea. I already solved it so you can DM me because its Pro.
3rd Apr 2020, 10:46 PM
Kevin ★
+ 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.
4th Apr 2020, 5:28 PM
Kevin ★
+ 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‼️🙂
6th Apr 2020, 7:52 PM
Janusz Bujak 🇵🇱
Janusz Bujak 🇵🇱 - avatar
+ 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
5th Jan 2021, 7:15 PM
Erik Gordon-Quaicoe
Erik Gordon-Quaicoe - avatar
+ 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‼️😃
6th Jan 2021, 9:52 AM
Janusz Bujak 🇵🇱
Janusz Bujak 🇵🇱 - avatar
+ 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))
6th Jan 2021, 10:51 AM
Erik Gordon-Quaicoe
Erik Gordon-Quaicoe - avatar
+ 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)
20th Feb 2021, 9:30 PM
Amir Mehrabi Jorshari
+ 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)
1st Mar 2021, 2:36 AM
黄海登
黄海登 - avatar