Skip to content
DeepForgeby svx
All problems
EasyLinear Algebrala-306

Sum of All Matrix Entries

Problem

Sum every entry of a matrix A.

Return the total of all elements across all rows and columns. The empty matrix sums to 0.

Hint

Sum each row first, then sum the row totals.

Test cases

case 1
in: [[[1,2],[3,4]]]
expected: 10
case 2
in: [[[1,-2,3],[-4,5,-6]]]
expected: -3
case 3
in: [[[7]]]
expected: 7
case 4
in: [[[0.5,1.5],[2.5,3.5]]]
expected: 8
case 5
in: [[]]
expected: 0
Starter codePython
def matrix_entry_sum(A):
    # Your code here
    pass

5 test cases · run your code against them in the editor