0% found this document useful (0 votes)
8 views3 pages

Matrix Multiplication in Python Code

Fds practical

Uploaded by

Sakshi Bhosale
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)
8 views3 pages

Matrix Multiplication in Python Code

Fds practical

Uploaded by

Sakshi Bhosale
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

Name: Kolekar Rohini Murlidhar

Class: S.E Computer

Div: B

# Multiplication of two matrices

row1 = int(input(Enter the number of rows:)

col1 = int(input("Enter the number of columns:)

c=0

# Initialize matrix

matrixa = []

matrixb = []

resultmatrix = []

print(Enter the entries rowwise:)

# For user input

print(Enter the entries for matrix A:\n)

for i in range(row1): # A for loop for row entries

a = []

for j in range(col1): # A for loop for column entries

[Link](int(input()))

[Link](a)

print(matrixa)

print(matrix is:)
# For printing first matrix

for i in range(row1):

for j in range(col1):

print(format(matrixa[i][j]), end= )

print()

print(Enter entries for matrix B:\n)


row2 = int(input(Enter the number of rows:))

col2 = int(input(Enter the number of columns:))

for i in range(row2): # A for loop for row entries


a = []

for j in range(col2): # A for loop for column entries

[Link](int(input()))

[Link](a)

print(matrix is:)

# For printing second matrix

for i in range(row2):

for j in range(col2):
print(format(matrixb[i][j]), end= )

print()

# For matrix Multiplication

for i in range(row1):

a = []
for j in range(col2):

for k in range(row2):

c = c + matrixa[i][k] * matrixb[k][j]

[Link](c)

c=0

[Link](a)

print(Result matrix for Multiplication is:)

# For printing the result matrix

for i in range(row1):

for j in range(col2):

print(format(resultmatrix[i][j]), end=)

print()

Output:

Enter the number of rows:2

Enter the number of columns:2

Enter the entries rowwise:

Enter the entries for matrix A:


3

[[3, 4], [3, 4], [4, 2], [4, 2]]

matrix is:

3 4

3 4

Enter entries for matrix B:

Enter the number of rows:2

Enter the number of columns:2

matrix is:

3 6

3 6

Result matrix for Multiplication is:

9 12

9 12

You might also like