+ 2
How can i impliment matrix multiplication using the numpy library in python?
I created a numpy array on my program and I want to perform matrix multiplication/dot product on the array. Can someone help me ASAP?
3 Antworten
+ 5
You can use the @ operator or the matmul function. (Python 3.5 or higher)
import numpy as np
a = np.array([[1, 2],
[3, 4]])
b = np.array([[5, 6],
[7, 8]])
print(a @ b) # OR print(np.matmul(a, b))
Output:
[[19, 22],
[43, 50]]
For older versions of Python, you could do a.dot(b), but @ is the recommended way.
0
Use special methods
0
Use special methods