How to solve Average of Rows end of module project from Data Science with Python course | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to solve Average of Rows end of module project from Data Science with Python course

Hi, I'm really stuck on this program and don't even know where to begin. I didn't really understand the Data Manipulation module even though I read through it thoroughly, and I'm not sure if the information given can even solve this problem. I've read through the 2 other questions about this challenge but they didn't help either. Please can you guide me in the right direction? I don't even understand the instructions even though I read through them multiple times. Thanks.

31st Dec 2020, 1:57 AM
Chinwendu Mere
19 Answers
+ 5
(2) Hints: --> You can create a list first then place all the rows in there then make it an array later --> To find the mean of each rows, use np.mean(array, axis=1) - - - - - - - - - - - - - - - - - Getting the Rows input will look like this. SAMPLE INPUT: 3 2 #so here the 2 dimensional array has 3 rows and 2 columns lst = [ ] for i in range(3): lst.append(input().split()) - - - - - - - - - - - - - - - - lst is our temporary list to store each rows then later on, we will convert it to an numpy array and it will be a 2 dimensional array. This will just serve as a guide for you and it is up to you how you will make this work. Thanks and Good Luck!
31st Dec 2020, 2:21 AM
noteve
noteve - avatar
+ 5
Hi Chinwendu Mere (1) First, I recommend you to import numpy Module as it will help you solve the problem easily. I will summarize the instruction for you to understand. - - - - - - - - - - - - - - The first two numbers (e.g. 2 2) are the no. of Rows and no. of Columns respectively. It will serve as your guide for getting your inputs. Next. You need to find the average of rows which means each element of the final answer are average of each rows. For Example [2, 4] [1, 5] Here the first row has the number 2 and 4, and their average or the mean can be solved by: (2+4) / 2 = 3 # same with second row (1+5) / 2 = 3 Final Answer: >> [3, 3] - - - - - - - - - - - - But this will be easier using NumPy Module, because numpy has the method np.mean Unfortunately, we cannot just give you the solution as we believe it will prevent you from learning. But If you already have the code and you got errors or bugs, feel free to post here in Q&A so we may help you. So I think you should start now. Good Luck!
31st Dec 2020, 2:18 AM
noteve
noteve - avatar
+ 3
《 Nicko12 》 Thank you! Your explanation really helped
31st Dec 2020, 11:08 AM
Chinwendu Mere
+ 3
Erik Gordon-Quaicoe In the same problem? Ok, but I think it is better if you post your own question, and show your attempt so I can help somehow. Thanks
6th Jan 2021, 1:28 AM
noteve
noteve - avatar
+ 3
Erik Gordon-Quaicoe Since I think you dont have the Inbox feature yet, I'll just send it here. If you have more questions feel free to ask. Thanks https://code.sololearn.com/cSQb4385ZIcE/?ref=app
6th Jan 2021, 11:08 AM
noteve
noteve - avatar
+ 3
Chinwendu Mere Just add. round(2) to last line of your code. Because based on the problem, numbers should be rounded to 2 decimal places. ☺ print(np.array(means).round(2))
6th Jan 2021, 11:33 AM
noteve
noteve - avatar
+ 1
《 Nicko12 》 My problem is how i can input the rows in the project. because on my pc outside the project i have done it and it works i followed your steps and explanations.
6th Jan 2021, 7:57 AM
Erik Gordon-Quaicoe
Erik Gordon-Quaicoe - avatar
+ 1
《 Nicko12 》 when i enter the rows in format stated in the instruction eg. 3 2 i get invalid syntax
6th Jan 2021, 8:03 AM
Erik Gordon-Quaicoe
Erik Gordon-Quaicoe - avatar
+ 1
can you show your code (save it in a cod bit btw)
6th Jan 2021, 9:58 AM
noteve
noteve - avatar
+ 1
《 Nicko12 》 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:50 AM
Erik Gordon-Quaicoe
Erik Gordon-Quaicoe - avatar
+ 1
By the way, Chinwendu Mere Did you solve it?
6th Jan 2021, 11:08 AM
noteve
noteve - avatar
+ 1
Chinwendu Mere Can I see your attempt?
6th Jan 2021, 11:15 AM
noteve
noteve - avatar
6th Jan 2021, 11:25 AM
Chinwendu Mere
+ 1
《 Nicko12 》 Thank you!
6th Jan 2021, 11:36 AM
Chinwendu Mere
0
can anyone help me ?
5th Jan 2021, 8:03 PM
Erik Gordon-Quaicoe
Erik Gordon-Quaicoe - avatar
6th Jan 2021, 10:49 AM
Erik Gordon-Quaicoe
Erik Gordon-Quaicoe - avatar
0
《 Nicko12 》 No I didn't, as it didn't work for the last 2 test cases which were hidden
6th Jan 2021, 11:15 AM
Chinwendu Mere
0
Erik Gordon-Quaicoe's answer was what I was thinking but I didn't the 'astype' method. The only thing he is missing is to round. Thanks!
25th Feb 2021, 10:10 PM
Emilio Linthon
0
I've made this recently. Don't know i that could help ya, but take it. ``` n, p = [int(x) for x in input().split()] import numpy as np print(np.mean(np.array([[float(x) for x in input().split()] for i in range(n)]), axis=1).round(2)) ```
8th Oct 2021, 10:42 AM
Manuel Juan Morales Amat
Manuel Juan Morales Amat - avatar