可能出现重复的原因是因为在同一组中可能存在相同的客户点坐标,导致在寻找该坐标在dataset中的序号时,可能会找到多个相同的序号。为了避免重复,可以在向customer_index中添加序号时,先判断该序号是否已经存在于列表中,如果不存在再加入。修改后的代码如下:

customer_index=[[] for _ in range(len(final_clusters))] for i,cluster in enumerate(final_clusters): for j in final_clusters[i]: index = np.where(j==dataset)[0][0] if index not in customer_index[i]: customer_index[i].append(index)

这样可以保证每个点只会被添加一次,避免了重复。


原文地址: https://www.cveoy.top/t/topic/e3cO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录