i'm having a little issue when adding2 matrices on python, according to my understanding the program should be:
being n the number of rows and columns since for my purposes, all the matrices are going to be N x N
as a result i get:
[2, 6, 18]
when i sould get:
[[2, 6, 18],[10,12,6],[4,10,16]]
i know i'm doing it the wrong way, i just don't know how to fix it, any help would be greatly appreciated!!
Code:
m1=[[1,3,9],[5,6,3],[2,5,8]] m2=[[1,3,9],[5,6,3],[2,5,8]] n=3 def sumamat(a,b): z=[] for i in range (n): for j in range (n): x=m1[i][j]+m2[i][j] z.append(x) return z print(sumamat(m1,m2))
as a result i get:
[2, 6, 18]
when i sould get:
[[2, 6, 18],[10,12,6],[4,10,16]]
i know i'm doing it the wrong way, i just don't know how to fix it, any help would be greatly appreciated!!
Comment