New course! Every coder should learn Generative AI!
Try a free lesson+ 1
I did this but always returns an error for float type
for i in range(n) Alist = list(map(float, input().split())) Row= np.array(Alist) Print(row.mean())
8 Answers
+ 4
Norika Gilbert ,
can you please give us the lesson / exercise number? i would like to see the original task description.
thanks a lot!
+ 3
Norika Gilbert ,
the code seems not to be complete. can you please put the complere code in playground and link it here?
thanks!
+ 2
If I run your code with
2 2
1.2 2.3
3.4 4.5
it works...
I would like to add that alist will be overwritten on each iteration of the for-loop. I assume you want to append alist to matrix?
+ 1
import numpy as np
import statistics
n, p = [int(x) for x in input().split()]
matrix=[]
for i in range(n):
alist = list([float(x) for x in input().split()])
arr = np.array(statistics.mean(alist))
print(arr)
+ 1
Lothar it seems to be Average of Rows from the Data Science Course
-----
In a matrix, or 2-d array X, the averages (or means) of the elements of rows is called row means.
Task
Given a 2D array, return the rowmeans.
Input Format
First line: two integers separated by spaces, the first indicates the rows of matrix X (n) and the second indicates the columns of X (p)
Next n lines: values of the row in X
Output Format
An numpy 1d array of values rounded to the second decimal.
2 2
1.5 1
2 2.9
+ 1
However with this input there should be no type error.
0
Changed a bit but still get type converting errors in my spyder compiler
0
What does the input look like?