Your code works fine. Please note that when the inputs to np.dot()
are matrices, np.dot()
performs matrix multiplication
In [18]: a = np.array([[1, 5, 7], [6, 8, 9]])
...: b = np.array([[1, 8, 8], [5, 8, 0], [8, 9, 0]])
...:
# @ is equivalent to `np.dot()` and `np.matmul()` in Python 3.5 and above
In [19]: a @ b
Out[19]:
array([[ 82, 111, 8],
[118, 193, 48]])
In [20]: (a @ b).shape
Out[20]: (2, 3)
# sanity check!
In [22]: a @ b == np.matmul(a, b)
Out[22]:
array([[ True, True, True],
[ True, True, True]], dtype=bool)
Note on @
: It was introduced in Python 3.5 as a dedicated infix operator for matrix multiplication
This is because some confusion existed whether *
operator does matrix multiplication or element-wise multiplication. So, to eliminate confusion, a dedicated operator @
was designated for matrix multiplication. So,
*
performs element-wise multiplication
@
performs matrix multiplication (dot product)