question archive Complete the function below that returns the sum of all rows in a 2-D matrix as a row vector
Subject:Computer SciencePrice: Bought3
Complete the function below that returns the sum of all rows in a 2-D matrix as a row vector. For example, given matrix
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
...
[90, 91, 92, 93, 94],
[95, 96, 97, 98, 99]])
it should return
array([ 950, 970, 990, 1010, 1030])
This function should return a np.ndarray of shape (arr.shape[0], ) or (-1, ), given the input 2D matrix arr.
Note that -1 is a kind of wildcard or inferred value in the numpy (re)shaping context.
def calc_row_sum(arr):
""" This function calculates the sum of all rows in a 2D matrix "arr". """
row_sum = None
# YOUR CODE HERE
#raise NotImplementedError()
return row_sum