0% found this document useful (0 votes)
25 views5 pages

Practical No.3

Uploaded by

Paras Kamble
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views5 pages

Practical No.3

Uploaded by

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

Practical No.

Name:- swapnil Manish


Paras Chandan Suryavanshi
Kamble
Roll No:- S213074
S213085
Class:- SE
Division:- C
Batch:- C3

Problem Statement:-Write a python program to compute following computation


on matrix.

1) Addition of two matrices


2) Subtraction of two matrices
3) Multiplication of two matrices 4) Transpose of matrix

code:-
INPUT:-
matrix_A=[] matrix_B=[]

def matrix(): matrix

= [] for i in range(0,2):

a=[] for j in

range(0,2):

n=int(input("Enter the number:"))


a.append(n) matrix.append(a) for i
in
range(0,2): for j in range(0,2):
print(matrix[i][j],end=" ")

print("\n") return(matrix)

matrix_A=matrix()

matrix_B=matrix() Add=[]

for i in range(0,2): c=[]

for j in range(0,2):

b=0

c.append(b)

Add.append(c) def

Addition(): for i in

range(0,2): for j in

range(0,2):

Add[i][j]=matrix_A[i][j]+matrix_B[i][j]

return(Add) Addition() print("Addition of

matrix is:",Addition())

Sub=[] for i in

range(0,2): c=[]

for j in range(0,2):

b=0

c.append(b)

Sub.append(c) def

Subtraction(): for i
in range(0,2): for j in

range(0,2):

Sub[i][j]=matrix_A[i][j]-matrix_B[i][j]

return(Sub) Subtraction()

print("Subtraction of matrix is:",Subtraction())

Mult=[] for i in

range(0,2): c=[]

for j in range(0,2):

b=0

c.append(b)

Mult.append(c) def

Multiplication(): for i in

range(0,2): for j in

range(0,2): for k in

range(0,2):

Mult[i][j]=Mult[i][j]+matrix_A[i][k]*matrix_B[k][j]

return(Mult) a=Multiplication() print("Multiplication of matrix

is:",a)

Trans1=[] for i in
range(0,2): c=[]
for j in range(0,2):
b=0
c.append(b)

Trans1.append(c) def Transpose():


for i in range(0,2): for j in

range(0,2):

Trans1[i][j]=matrix_A[j][i]

return(Trans1) b=Transpose()

print("Transpose of matrix_A is:",b)

Trans2=[] for i in

range(0,2): c=[]

for j in range(0,2):

b=0

c.append(b)

Trans2.append(c) def Transpose():

for i in range(0,2): for j in

range(0,2):

Trans2[i][j]=matrix_B[j][i]

return(Trans2) c=Transpose()

print("Transpose of matrix_B is:",c)

OUTPUT:-
Enter the number:1
Enter the number:2

Enter the number:3

Enter the number:4

12

34

Enter the number:7

Enter the number:8

Enter the number:5


Enter the number:6

78

56

Addition of matrix is: [[8, 10], [8, 10]]

Subtraction of matrix is: [[-6, -6], [-2, -2]]

Multiplication of matrix is: [[17, 20], [41, 48]]

Transpose of matrix_A is: [[1, 3], [2, 4]]

Transpose of matrix_B is: [[7, 5], [8, 6]]

You might also like