Calculate Sum Get User Input Patterns Program Find Area of CircleFind Area of Rectangle Perimeter of Rectangle Find Even and Odd Numbers Find Sum of Digit in Python Find Factorial in PythonPrint Fibonacci Series Check Armstrong Number Reverse a Number Check Palindrome Number Swap Two Numbers Matrix MultiplicationFind Perfect NumberAdd Two Matrix in Python Find Sum of Squares Find Sum of Cubes Find URL in String
Find Largest in List Find Duplicate in List Check Alphabet Remove Duplicate Elements from List Reverse List Elements Find Element in Python List Interchange first and last element in List Find Even Numbers in List Find Length of a List Find Sum of list Elements Find Elements in List Get the product of List elements Interchange List Elements Find Smallest Elements in List Find Max Value in a List
A matrix is a list of lists in Python that represents data into rows and columns. We can multiply one matrix with another matrix with the help of loops. Let's see some examples.
# Python Program to Multiply Two Matrix
# First Matrix
A = [[20, 10], [5, 6]]
# Second Matrix
B = [[10, 20], [7, 4]]
# Third Matrix to store result
Z = [[0, 0], [0, 0]]
# Iterate First Matrix row-wise
for i in range(len(A)):
# Iterate Second Matrix column-wise
for j in range(len(B[0])):
# Iterate Second Matrix row-wise
for k in range(len(B)):
Z[i][j] += A[i][k] * B[k][j]
print("Multiplication of Two Matrices")
for r in Z:
print(r)
Output:
Multiplication of Two Matrices
[270, 440]
[92, 124]
# Python Program to Multiply Two Matrix
# First Matrix
A = [[20, 10], [5, 6]]
# Second Matrix
B = [[10, 20], [7, 4, 10]]
# Third Matrix to store result
Z = [[0, 0], [0, 0]]
# Iterate First Matrix row-wise
for i in range(len(A)):
# Iterate Second Matrix column-wise
for j in range(len(B[0])):
# Iterate Second Matrix row-wise
Z = [[sum(a * b for a, b in zip(A_row, B_col))
for B_col in zip(*B)]
for A_row in A]
print("Multiplication of Two Matrices")
for r in Z:
print(r)
Output:
Multiplication of Two Matrices
[270, 440]
[92, 124]