Sunday, October 18, 2015

Matrix addition in Python


3 * 3 matrix addition

matrix1=[[2]*3] * 3
matrix2=[[10] * 3] * 3
matrix3=[[0] * 3] * 3
print matrix1
print matrix2

for i in range(3):
    for j in range(3):
        matrix3[i][j]=matrix1[i][j] + matrix2[i][j]
print matrix3