Gridi Kono
Gridi Kono

Reputation: 45

numpy ValueError: operands could not be broadcast together with shapes

thetaU = np.linalg.inv(np.linalg.inv(theta) + theta2_input**(-1)*np.transpose(X_test[i]) * X_test[i])

When I execute the following inside one of my functions.. I get the following error:

ValueError:  operands could not be broadcast together with shapes (2,100) (100,2)

I'm kind of new to Python and would appreciate any help. Thank you.

Upvotes: 2

Views: 1598

Answers (1)

DYZ
DYZ

Reputation: 57033

In NumPy, operator * does not represent matrix multiplication. It multiplies two arrays element-wise. Replace it with np.matmul() or np.dot():

np.matmul(np.transpose(X_test[i]), X_test[i]))

Upvotes: 2

Related Questions