I can't figure out the error please check

--------------------------------------------------- MY CODE IS: query_x = np.array([150,80]) plt.scatter(X[:,0],X[:,1],c=Y) plt.scatter(query_x[0],query_x[1],color=‘red’) plt.show() def dist(x1,x2): return np.sqrt(sum((x1-x2)**2)) def knn(X,Y,queryPoint,k=5): vals=[] m=X.shape[0] for i in range(m): d = dist(queryPoint,X[i]) vals.append((d,Y[i])) vals = sorted(vals) #NeAREST FIRST K POINTS vals = vals[:k] vals = np.array(vals) print(vals) knn(X,Y,query_x)//Calling the Function here. ERROR: ------------------------ ValueError Traceback (most recent call last) in ----> 1 knn(X,Y,[150,80]) in knn(X, Y, queryPoint, k) 7 8 for i in range(m): ----> 9 d = dist(queryPoint,X[i]) 10 vals.append((d,Y[i])) 11 vals = sorted(vals) in dist(x1, x2) 1 def dist(x1,x2): ----> 2 return np.sqrt(sum((x1-x2)**2)) 3 4 def knn(X,Y,queryPoint,k=5): 5 vals=[] ValueError: operands could not be broadcast together with shapes (2,) (7,)

Hey @YashSINGHAI, print shape/length of x1 and x2 you are passing to the dist function. It seems that in line d = dist(queryPoint,X[i]) , X[i] has 7 values and query point has only 2 values. Shapes of both these vectors must be same. So use queryPoint having 7 values and not 2.

Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section. :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.