0

Data Science - Average of Rows

Data Science - Average of Rows Question: 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] Solution: import numpy as np n, p = [int(x) for x in input().split()] lista = [] for i in range(n): lista.append(input().split()) print(np.array(lista).astype(np.float16).mean(axis=1).round(2)) Solution fails test case: Your output: [1.5 0.75 0.65] Expected output: [1.5 0.75 0.65] Notice the space before 0.75 means the test case fails. How may I remove the whitespace thanks.

29th Jul 2022, 10:05 PM
D33pesh
D33pesh - avatar
4 Respostas
0
please provide your test input to test
30th Jul 2022, 10:26 AM
takrim
takrim - avatar
0
n, p = [int(x) for x in input().split()]
30th Jul 2022, 10:18 PM
D33pesh
D33pesh - avatar
0
D33pesh i said which input gave you the output [1.5 0.75 0.65]
30th Jul 2022, 10:19 PM
takrim
takrim - avatar
0
Input 3 2 1 2 1 0.5 1 0.3
31st Jul 2022, 9:05 PM
D33pesh
D33pesh - avatar