发布时间:2019-09-03 08:55:52编辑:auto阅读(2577)
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安装使
51922
51694
42013
38852
33340
30312
28949
23963
23880
22248
351°
2579°
3251°
2704°
2683°
3420°
2649°
3482°
5723°
5522°