0% found this document useful (0 votes)
7 views1 page

DB925799 - Assignment10

The document contains code to perform element-wise addition, subtraction and multiplication on two 3x3 matrices X and Y. It initializes result matrix to zeros and uses nested for loops to calculate each element of the result matrices for the three operations and prints the output.

Uploaded by

Cheong Tong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

DB925799 - Assignment10

The document contains code to perform element-wise addition, subtraction and multiplication on two 3x3 matrices X and Y. It initializes result matrix to zeros and uses nested for loops to calculate each element of the result matrices for the three operations and prints the output.

Uploaded by

Cheong Tong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Name: Cheong Tong Chon

Student No. :DB925799


CISC1001 Programming Science
Assignment10
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]]

for i in range(len(X)):
for j in range(len(X[0])):
result[i][j] = X[i][j] + Y[i][j]
print('X+Y=')
for r in result:
print(r)

for i in range(len(X)):
for j in range(len(X[0])):
result[i][j] = X[i][j] - Y[i][j]
print('X-Y=')
for r in result:
print(r)

for i in range(len(X)):
for j in range(len(Y[0])):
for k in range(len(Y)):
result[i][j] += X[i][k] * Y[k][j]
print('X*Y=')
for r in result:
print(r)

You might also like