Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

sum all values in a matrix python

#construct the matrix
matrix = [[1, 2], [4, 3]]

#iterate over the matrix summing all elements in the row
#give those row summations into a list
#sum the list to give you the answer
ans = sum([sum(row) for row in matrix])

print(ans)
10
 
PREVIOUS NEXT
Tagged: #sum #values #matrix #python
ADD COMMENT
Topic
Name
9+5 =