Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Create Multiplication of two matrices
  • Loading branch information
ravi10393 authored Oct 15, 2020
commit 02be51fc5ada50d41ca37e8b321ddc650f8115aa
28 changes: 28 additions & 0 deletions Multiplication of two matrices
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Program to multiply two matrices using nested loops

# take a 3x3 matrix
A = [[12, 7, 3],
[4, 5, 6],
[7, 8, 9]]

# take a 3x4 matrix
B = [[5, 8, 1, 2],
[6, 7, 3, 0],
[4, 5, 9, 1]]

result = [[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]

# iterating by row of A
for i in range(len(A)):

# iterating by coloum by B
for j in range(len(B[0])):

# iterating by rows of B
for k in range(len(B)):
result[i][j] += A[i][k] * B[k][j]

for r in result:
print(r)