generate functionTue, 28 Feb 2023

The input is a two-dimensional array X . Write a function that for each row (x=(x1,x2,…,xn) of array X builds a row s=(s1,s2,…,sn) , where sk=x1+...+xk , and then outputs an array from built lines.Use the numpy library (the cumsum function will help you.) The output of the function should be a two-dimensional numpy array of the same shape as X.​

def row_sum(matrix): return matrix.cumsum(axis=1)

Questions about programming?Chat with your personal AI assistant