Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 1 is different from 3)

I have written code using matmul, but I am getting the following error:

   "ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 1 is different from 3)"

Code:

    R = [[0.40348195], [0.38658295], [0.82931052]]
    V = [0.33452744, 0.33823673, 0.32723583]
    print("Rt_p: ", R)
    B = np.matmul(V,np.transpose(R))/pow(LA.norm(R), 2)
    print("B", B)
like image 982
BiSarfraz Avatar asked Dec 13 '19 06:12

BiSarfraz


2 Answers

Try to check your X_train shape and then check the shape of the test data which you input into the .predict() function. if the number of features are different like X_train(2323,22) and for test data (3534,20) then it will show this type of erro

like image 73
Umesh Tikhe Avatar answered Oct 07 '22 20:10

Umesh Tikhe


You are transposing a Matrix with 3 rows and 1 column to a Matrix with 3 columns and 1 row. Then you are multiplying it with a similar Matrix (also 3 columns 1 row) which is incorrect mathematically. So you can either remove the transpose function or define your R Matrix as 1 row 3 columns and then transpose it. Check this for further information.

like image 27
IcesHay Avatar answered Oct 07 '22 19:10

IcesHay