Let\'s say we have two matrices A and B and let matrix C be A*B (matrix multiplication not element-wise). We wish to get
A
B
C
A*B
def diag(A,B): diags = [] for x in range(len(A)): diags.append(A[x][x] * B[x][x]) return diags
I believe the above code is that you're looking for.