Python Program to add two matrices using nested loop

Published: 04 November 2022
on channel: Tech Tips
85
0

Program to add two matrices using nested loop

X = [[1,2,3],
[4 ,5,6],
[7 ,8,9]]

Y = [[9,8,7],
[6,5,4],
[3,2,1]]


result = [[0,0,0],
[0,0,0],
[0,0,0]]

iterate through rows
for i in range(len(X)):
iterate through columns
for j in range(len(X[0])):
result[i][j] = X[i][j] + Y[i][j]

for r in result:
print(r)
Output
[10, 10, 10]
[10, 10, 10]
[10, 10, 10]


On this page of the site you can watch the video online Python Program to add two matrices using nested loop with a duration of hours minute second in good quality, which was uploaded by the user Tech Tips 04 November 2022, share the link with friends and acquaintances, this video has already been watched 85 times on youtube and it was liked by 0 viewers. Enjoy your viewing!