Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MatrixMultiplier.py #50

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
36 changes: 21 additions & 15 deletions MatrixMultiplier.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@


# taking a 3x3 matrix
A = [[12, 7, 3],
# Define the matrices A and B
A = [
[12, 7, 3],
[4, 5, 6],
[7, 8, 9]]

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

B = [
[5, 8, 1, 2],
[6, 7, 3, 0],
[4, 5, 9, 1]]

# result will be 3x4
result = [[sum(a * b for a, b in zip(A_row, B_col))
for B_col in zip(*B)]
for A_row in A]
#Now displaying the result
[4, 5, 9, 1]
]

# Initialize the result matrix with zeros
result = [[0 for _ in range(len(B[0]))] for _ in range(len(A))]

# Perform matrix multiplication
for i in range(len(A)):
for j in range(len(B[0])):
for k in range(len(B)):
result[i][j] += A[i][k] * B[k][j]

# Display the result
for r in result:
print(r)