How to perform matrix multiplication using Python NumPy?
We can use the following Python code to perform matrix multiplication using NumPy.
import numpy A = numpy.array([[1, 2, 3], [4, 5, 6]]) B = numpy.array([[7, 8, 9], [10, 11, 12], [13, 14, 15]]) C = numpy.matmul(A, B) print("A: \n", A) print("B: \n", B) print("C = A x B: \n", C)
Here, we are first creating two matrices A and B using the numpy.array() function. After that, we are using the numpy.matmul() function with the arguments A and B to multiply the two matrices A and B.
The output of the mentioned program will be:
A: [[1 2 3] [4 5 6]] B: [[ 7 8 9] [10 11 12] [13 14 15]] C = A x B: [[ 66 72 78] [156 171 186]]






0 Comments