ERROR please check once and revert

ValueError Traceback (most recent call last)
in
22 face_section = cv2.resize(face_section,(100,100))
23
—> 24 out = knn(trainset,face_section.flatten())
25 pred_name = names[int(out)]
26 cv2.putText(frame,pred_name,(x,y-10),cv2.FONT_HERSHEY_SIMPLEX,1,(255,0,0),2,cv2.LINE_AA)

in knn(train, test, k)
16 labels = np.array(dk)[:, -1]
17 #GET FREQUENCIES
—> 18 output = np.unique(labels,return_counts=True)
19 #Find max frequency
20 index = np.argmax(output[1])

<array_function internals> in unique(*args, **kwargs)

c:\users\hp\appdata\local\programs\python\python37\lib\site-packages\numpy\lib\arraysetops.py in unique(ar, return_index, return_inverse, return_counts, axis)
261 ar = np.asanyarray(ar)
262 if axis is None:
–> 263 ret = _unique1d(ar, return_index, return_inverse, return_counts)
264 return _unpack_tuple(ret)
265

c:\users\hp\appdata\local\programs\python\python37\lib\site-packages\numpy\lib\arraysetops.py in unique1d(ar, return_index, return_inverse, return_counts)
309 aux = ar[perm]
310 else:
–> 311 ar.sort()
312 aux = ar
313 mask = np.empty(aux.shape, dtype=np.bool
)

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Hello @YashSINGHAI,

Without your code it would be really tough for us to help you in debugging this error. Kindly share your code through Colab or Coding Blocks IDE.

HERE IS THE CODE IN IDE SAVED OPEN THE LINK -> https://ide.codingblocks.com/s/235990

It’s been 3 days you haven’t replied to my queries.???

Hello @YashSINGHAI,

def knn(train,test,k=5):
    dist=[]
    
    
    for i in range(train.shape[0]):
        ix = train[i, :-1]
        iy = train[i, -1] #<- HERE I HAVE UPDATED THE CODE
        d = distance(test,ix)
        dist.append([d,iy])
    #SORT BASED ON THE DISTANCE

In knn function, I have updated a line which I have commented above. Change this in your code and try running it again and let us know if this worked.

Also, if there are multiple files, try sharing it in multiple code links, everything in one place is pretty complex to understand, also, try to share a screenshot of the error rather than copying the entire thing in the code sheet itself.

Thanks