实现两个点集的欧式距离和索引值寻找(含有两种解法,for循环和矩阵操作)
一,直接for循环 两个点集points1,points2,用dist来存储距离 points1=np.array([[1,2],[3,4]]) points2 = np.array([[5, 6],[7,8]]) dist = np.zeros(shape=[points1.shape[0],points2.shape[0]]) for i in range(points1.shape[0]): for j in range(points2.shape[0]): print(points1[i, :] - points2[j, :]) 遍历两个点集的索引相减值 加上这句话 print(np.square(points1[i, :] - points2[j, :])) print(np.sum(np.square(points1[i, :] - points2[j, :]))) print(np.sqrt(np.sum(np.square(points1[i, :] - points2[j, :])))) points1=np.array([[1,2],[3,4]]) points2 = np.array([[5, 6],[7,8]]) dist = np.zeros(shape=[points1.shape[0],points2.shape[0]]) for i in range