Data Science - Average of Rows. Has anybody solved this Code Coach Challenge⁉️ - SOLVED | Sololearn: Learn to code for FREE!

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

4/3/2020 10:18:11 PM

Janusz Bujak 🇵🇱

20 Answers

New Answer

+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‼️☹️

+7

I have used np.around and it worked! https://docs.scipy.org/doc/numpy/reference/generated/numpy.around.html

+7

Mihai Apostol [ ⚓ INACTIVE] So is there any other code-coach challenge that cannot be seen directly but it exist🙄🤔?

+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

+3

No idea. I already solved it so you can DM me because its Pro.

+3

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

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)