- 1

Data science average of rows

Data Science - Average of Rows 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 Sample Output [1.25 2.45] My Code: import numpy as np n, p = [int(x) for x in input().split()] my_list = [] for i in range(n): my_list.append(list(float(x) for x in (input().split()))) my_list_ar = np.array(my_list) my_list_ar.reshape(n, p) print(np.around((my_list_ar.mean(axis=1)), decimals=2)) Input 3 2 1 2 1 0.5 1 0.3 Your Output [1.5 0.75 0.65] Expected Output [1.5 0.75 0.65] It says the error is because there is a space between 1.5 and 0.75

28th Jul 2022, 11:04 PM
warren fernandes
warren fernandes - avatar
4 Answers
0
I made a test on the playground of my own code, and it also produced a double space between 1.5 and 0.75 It's also important that the input is correct, or else you end up getting an error about something in numpy that is deprecated.
29th Jul 2022, 6:16 AM
Jan
Jan - avatar
0
I made some tests on the test cases with the same code that earlier passed all test cases. First, it failed test case 2, 3 and 4. Then I converted the output to a string without the extra space, and then it passed test case 2, but it still failed 3 and 4. That's weird.
29th Jul 2022, 12:33 PM
Jan
Jan - avatar
0
Hi!, did you managed to solve it? I'm haing the same problem with the extra spacing, and i'm still unable to figure out how to solve it :(
5th Aug 2022, 4:44 PM
Pedro Andres Modinger Hathaway
Pedro Andres Modinger Hathaway - avatar