From 74c895e824b0ce0099f672ead8e1b605b8a1497d Mon Sep 17 00:00:00 2001 From: MAYANK CHAUDHARI <65117236+mayankcs@users.noreply.github.com> Date: Wed, 28 Oct 2020 17:02:40 +0530 Subject: [PATCH] Python program to add two matrices Here we have pass to matrices in x and y variable respectively then by iterating through for loop , we have added it ! --- AddTwoMatrices.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 AddTwoMatrices.py diff --git a/AddTwoMatrices.py b/AddTwoMatrices.py new file mode 100644 index 0000000..5ae40be --- /dev/null +++ b/AddTwoMatrices.py @@ -0,0 +1,22 @@ +# Program to add two matrices using nested loop + +X = [[12,7,3], + [4 ,5,6], + [7 ,8,9]] + +Y = [[5,8,1], + [6,7,3], + [4,5,9]] + +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)