Reputation:
In the following code, why is there an output, mathematically it should give an error
import numpy as np
arr = np.array([[1., 2., 3.], [4., 5., 6.]])
out:
array([[1., 2., 3.],
[4., 5., 6.]])
arr*arr
out : array([[ 1., 4., 9.],
[16., 25., 36.]])
Upvotes: 0
Views: 50
Reputation: 86
The * operator multiplies values in place. It seems like you want the @ operator, which performs a dot product between the two matrices.
Example:
a = np.array([[1, 2])
b = np.array([[3], [5]])
a * b returns: [[3, 6],[5, 10]]
a @ b returns: 13
Upvotes: 2