I did this but always returns an error for float type | Sololearn: Learn to code for FREE!
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())

12th Dec 2021, 3:54 PM
Norika Gilbert
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!
12th Dec 2021, 6:40 PM
Lothar
Lothar - avatar
+ 3
Norika Gilbert , the code seems not to be complete. can you please put the complere code in playground and link it here? thanks!
12th Dec 2021, 4:00 PM
Lothar
Lothar - avatar
+ 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?
12th Dec 2021, 4:28 PM
Lisa
Lisa - avatar
+ 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)
12th Dec 2021, 4:06 PM
Norika Gilbert
+ 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
12th Dec 2021, 6:52 PM
Simon Sauter
Simon Sauter - avatar
+ 1
However with this input there should be no type error.
12th Dec 2021, 6:53 PM
Simon Sauter
Simon Sauter - avatar
0
Changed a bit but still get type converting errors in my spyder compiler
12th Dec 2021, 4:06 PM
Norika Gilbert
0
What does the input look like?
12th Dec 2021, 4:17 PM
Simon Sauter
Simon Sauter - avatar