+ 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.
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!
+ 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!
+ 3
ć Nicko12 ć Thank you! Your explanation really helped
+ 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
+ 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
+ 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))
+ 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.
+ 1
ć Nicko12 ć when i enter the rows in format stated in the instruction eg. 3 2 i get invalid syntax
+ 1
can you show your code (save it in a cod bit btw)
+ 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))
+ 1
By the way, Chinwendu Mere Did you solve it?
+ 1
Chinwendu Mere Can I see your attempt?
+ 1
ć Nicko12 ć Thank you!
0
can anyone help me ?
0
ć Nicko12 ć please check https://del.dog/ghuxutosyc
0
ć Nicko12 ć No I didn't, as it didn't work for the last 2 test cases which were hidden
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!
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))
```