Trying to understand the problem in DS for Python - Data Manipulation
I need help to see if I understand the problem correctly. The project problem is stated as follows: 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 The given first line of code is as follows: n, p = [int(x) for x in input().split()] Now this is how I understand this problem and given code line - please tell me where I got it wrong: The given line of code is there so one could input any two integers, n and p, that determine the shape of an array. A new line of code is needed to allow input of data into a new list. For example: v = [float(y) for y in input().split()] The next step should be to construct a numpy array with shape (n, p) The next step should be to reshape v to have the shape (n,p) Then it becomes simply a matter of applying arr.mean(axis = 1) to get the desired output. Now I know there is something wrong with the above understanding of the problem because SL is treating my second line v = [float(y) for y in input().split()] to create a one-dimensional array with two values (obviously). If I include a third line of code, say vtwo = [float(z) for z in input().split()] it will create a second array and I could then concatenate the two arrays v and vtwo before reshaping, but the problem with this approach is that it only works if n is 2. Which I could solve with some sort of loop but I am suspecting that my understanding of what n and p are is incorrect. Could you please clarify?? I've been stuck for 3 days now :(