Bootstrap

Sklearn计算二维矩阵中点坐标(x,y)两两之间的距离

'''
功能:
计算利用二维坐标表示的二维矩阵中,不同点之间的距离
------------------
输入:
二维矩阵,n行2列,每行可以代表二维空间的点坐标(x,y)
------------------
输出:
n×n的矩阵,其中n的物理意义是n个坐标点。
矩阵中的每个值代表不同点(x,y)之间的距离
'''
from sklearn.metrics.pairwise import pairwise_distances
import numpy as np


t = np.linspace(0, 2 * np.pi, 101)[0:100]
X1 = np.zeros((len(t), 2))
X1[:, 0] = np.cos(t)
X1[:, 1] = np.sin(t)
t = np.linspace(0, 2 * np.pi, 1001)[0:1000]
X2 = np.zeros((len(t), 2))
X2[:, 0] = 2 * np.cos(t) + 5
X2[:, 1] = 2 * np.sin(t)
X3 = np.zeros((len(t), 2))
X3[:, 0] = 3 * np.cos(t)
X3[:, 1] = 3 * np.sin(t) + 3
X = np.concatenate((X1, X2, X3), 0)
print(X)
D = pairwise_distances(X, metric='euclidean')
print(D)

参考:https://gist.github.com/ctralie/128cc07da67f1d2e10ea470ee2d23fe8

;