'finding mean of row of the 2Drray
----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]
MYANSWER:
import numpy as np
n, p = [int(x) for x in input().split()]
list_=[]
for i in range(n):
list_.append([])
rec=[float(value) for value in input().split()]
for j in rec:
list_[i].append(j)
#print(list_)
arr=np.array(list_)
#print(arr)
arr=arr.reshape(n,p)
print(arr.mean(axis=1))
PROBLEM: not every test case is satisfied.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
