发布时间:2019-09-03 08:55:52编辑:auto阅读(1907)
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安装使
47619
46017
36923
34491
29101
25747
24586
19729
19272
17768
5584°
6169°
5707°
5761°
6720°
5500°
5504°
6005°
5977°
7308°