31 lines
772 B
Python
31 lines
772 B
Python
|
import pandas as pd
|
||
|
import numpy as np
|
||
|
|
||
|
# 读取Excel文件中的数据
|
||
|
df = pd.read_excel("links.xls")
|
||
|
|
||
|
# 创建点的集合
|
||
|
points = set()
|
||
|
for index, row in df.iterrows():
|
||
|
points.add((row[0], row[1]))
|
||
|
points.add((row[2], row[3]))
|
||
|
|
||
|
# 为点分配唯一的整数标签
|
||
|
point_labels = {point: index for index, point in enumerate(points)}
|
||
|
|
||
|
# 创建一个空的邻接矩阵
|
||
|
num_points = len(points)
|
||
|
adj_matrix = np.zeros((num_points, num_points), dtype=int)
|
||
|
|
||
|
# 填充邻接矩阵
|
||
|
for index, row in df.iterrows():
|
||
|
point1 = (row[0], row[1])
|
||
|
point2 = (row[2], row[3])
|
||
|
|
||
|
point1_label = point_labels[point1]
|
||
|
point2_label = point_labels[point2]
|
||
|
|
||
|
adj_matrix[point1_label, point2_label] = 1
|
||
|
adj_matrix[point2_label, point1_label] = 1
|
||
|
|
||
|
print(adj_matrix)
|