How can this be done elegantly (Pythonic way)
You have two matrices A and B represented each by a list of lists.
You would like to calculate the overall sum over the matrix of element-wise product of A and B.
sample code:
sum = 0
nrows = len(A)
ncols = len(A[0])
for i in range(nrows):
for j in range(ncols):
sum += A[i][j]*B[i][j]
# interested finally in the value of sum
# return sum
for example if
A=[[1,2,3],[3,4,5]]
and
B=[[3,2,2],[1,1,1]]
the result is :
1*3 + 2*2 + 3*2 + 3*1 + 4*1 + 5*1 = 25