发布时间:2019-09-03 08:55:52编辑:auto阅读(1971)
from sklearn.neighbors import NearestNeighbors from random import choice X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]]) neigh = NearestNeighbors(n_neighbors = 5) neigh.fit(X) N=3 S = np.zeros(shape=(X.shape[0]*(N-1), X.shape[1])) S = np.vstack((X, S)) print S for i in xrange(X.shape[0]): nn = neigh.kneighbors(X[i].reshape(1, -1), return_distance=False) for n in xrange(N-1): nn_index = choice(nn[0]) #NOTE: nn includes T[i], we don't want to select it while nn_index == i: nn_index = choice(nn[0]) dif = X[nn_index] - X[i] # print dif gap = np.random.random() index = n + i * (N-1)+X.shape[0] print index S[index, :] = X[i,:] + gap * dif[:] print S
上一篇: python 多维数组的排序
下一篇: 巡风 win7 python3.7安装使
47905
46486
37396
34798
29368
26030
25000
20000
19618
18100
5836°
6475°
5982°
6003°
7114°
5954°
6004°
6493°
6457°
7835°