# findin eucliean distance and showing the 5 nearest neighbours
distarr=[]
for x in range(10000):
distarr.append(euclideanDistance(timages_array[x],images_array[x]))
# distarr[x]=euclideanDistance(timages_array[x],images_array[x])
pracarr=[]
ksmallneigh(pracarr,distarr,5) # k smallest neighbours in pracarr
for x in range(5):
print(label_array[pracarr[x]])
仅按降序排列数组的功能,这样我可以取出前5个元素
def ksmallneigh(pracarr,array1, k):
# Sort the given array arr in reverse
# order.
array1.sort(reverse=False)
#Print the first kth largest elements
for i in range(k):
pracarr.append(array1[i])
# pracarr[i]=array1[i]