- Related Questions & Answers
- Java program to multiply two matrices.
- C# program to multiply two matrices
- Program to multiply two matrices in C++
- How to Multiply Two Matrices using Python?
- C++ Program to Multiply two Matrices by Passing Matrix to Function
- How can Tensorflow be used to multiply two matrices using Python?
- How to multiply two matrices by elements in R?
- How to multiply two matrices using pointers in C?
- Java program to add two matrices.
- Java program to subtract two matrices.
- C# program to add two matrices
- Program for subtracting two matrices.
- C++ Program to Multiply two Numbers
- Python Program to check if two given matrices are identical
- How to Add Two Matrices using Python?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this article, we will learn about the solution to the problem statement given below.

**Problem statement **− We are given two matrices, we need to multiply them and print the result.

For two matrices to be multiplied columns of the first matrix must be identical to that of the rows of the second matrix

Each time this condition is evaluated to be true computation is performed

Now let’s observe the concept in the implementation below−

A = [[1, 2, 3], [4, 5, 6], [7, 8, 9] ] B = [[5, 3, 3], [6, 5, 4], [0, 2, 0] ] result= [[0, 0, 0], [0, 0, 0], [0, 0, 0] ] # iterating by row for i in range(len(A)): # iterating by column for j in range(len(B[0])): # iterating by rows for k in range(len(B)): result[i][j] += A[i][k] * B[k][j] for ele in result: print(ele)

[17, 19, 11] [50, 49, 32] [83, 79, 53]

A = [[1, 2, 3], [4, 5, 6], [7, 8, 9] ] B = [[5, 3, 3], [6, 5, 4], [0, 2, 0] ] # using built-in zip function result = [[sum(a * b for a, b in zip(A_row, B_col)) for B_col in zip(*B)] for A_row in A] for ele in result: print(ele)

[17, 19, 11] [50, 49, 32] [83, 79, 53]

In this article, we have learned how to multiply two matrices.

Advertisements