To perform matrix multiplication or to multiply two matrices in python, you have to choose three matrices. Initially, all the element of the third matrix will be zero. Now perform the matrix multiplication and store the multiplication result in the third matrix one by one as shown here in the program given below.
Following python program choose the two matrix and another empty matrix to perform and print the matrix multiplication:
# Python Program - Matrix Multiplication matrix1 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] matrix2 = [[10, 11, 12, 13], [14, 15, 16, 17], [18, 19, 20, 21]] rmatrix = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] for i in range(len(matrix1)): for j in range(len(matrix2)): for k in range(len(matrix2)): rmatrix[i][j] += matrix1[i][k] * matrix2[k][j] for r in rmatrix: print(r)
Here is the sample run of the above python program to illustrates how to perform matrix multiplication:
You may also like to learn or practice the same program in other popular programming languages: