npoints = 10
xmax=10
xmin=0
ymax=10
ymin=0
nd_coord = np.random.uniform(size=(npoints, 2))
nd_coord[:, 0] = nd_coord[:, 0]*(xmax-xmin)+xmin
nd_coord[:, 1] = nd_coord[:, 1]*(ymax-ymin)+ymin
# create a matrix with all possible distances
x_rep = np.tile(nd_coord[:, 0], [1, npoints])
y_rep = np.tile(nd_coord[:, 1], [1, npoints])
dist_matr = sp.coo_matrix(np.triu(((x_rep-x_rep.transpose)**2 + (y_rep-y_rep.transpose)**2)**0.5, 1));
# create the matrix of probabilities
prob_matr = alpha*sp.find('exp',-dist_matr/(beta*max(max(dist_matr))));
# generate the adjacency matrix
runi = sp.rand(dist_matr);
adj_matr = (runi>0) & (runi < prob_matr);
感谢您的意见
答案 0 :(得分:0)
transpose
是一种方法,您需要调用它。
(x_rep-x_rep.transpose())**2 + (y_rep-y_rep.transpose())**2)