Exercise 3: Sum the Rows of a Matrix

Write code that calculates the array produced by summing the entries of each row of a matrix.

We'll cover the following

Problem statement

In this exercise, you’re given a nested array. Sum the entries in each row of the matrix and return an array containing these sums.


For example, consider the following array:

nested_array = [
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9]

We get the following output in return:

[6, 15, 24]

Try it yourself

def sum_the_cols(nested_array)
result = []
# Start your code here
return result

Create a free account to access the full course.

Learn to code, grow your skills, and succeed in your tech interview

By signing up, you agree to Educative's Terms of Service and Privacy Policy