- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Multiply Two Matrices using Python?
Multiplication of two matrices is possible only when number of columns in first matrix equals number of rows in second matrix.
Multiplication can be done using nested loops. Following program has two matrices x and y each with 3 rows and 3 columns. The resultant z matrix will also have 3X3 structure. Element of each row of first matrix is multiplied by corresponding element in column of second matrix.
X = [[1,2,3], [4,5,6], [7,8,9]] Y = [[10,11,12], [13,14,15], [16,17,18]] result = [[0,0,0], [0,0,0], [0,0,0]] # iterate through rows of X for i in range(len(X)): for j in range(len(Y)): for k in range(len(Y)): result[i][j] += X[i][k] * Y[k][j] for r in result: print(r)
The result: [84, 90, 96] [201, 216, 231] [318, 342, 366]
- Python program to multiply two matrices
- How can Tensorflow be used to multiply two matrices using Python?
- How to multiply two matrices using pointers in C?
- C# program to multiply two matrices
- Java program to multiply two matrices.
- Program to multiply two matrices in C++
- How to multiply two matrices by elements in R?
- How to Add Two Matrices using Python?
- How to multiply corresponding values from two matrices in R?
- How to multiply two matrices in R if they contain missing values?
- C++ Program to Multiply two Matrices by Passing Matrix to Function
- How can Tensorflow be used to add two matrices using Python?
- Multiplication of two Matrices using Numpy in Python
- How to multiply matrices elements if matrices are stored in a list in R?
- Multiplication of two Matrices using Java