从两个词典生成欧氏距离矩阵?

时间:2017-07-13 15:51:24

标签: python dictionary random networkx shuffle

我有两个代表区域和Police_Dept的词典。我的目标应该是计算每个区域/ Police_Dept之间的欧氏距离。从这两个带networkx的词典开始,我创建了一个图表,如下面的代码所示:

This is the first dict representing areas

This is the second dict representing Police_Dept

现在我使用networkx生成图表:

G = nx.Graph()

#nodes with f=1 refers to area
i = 1
for k in data1:
    G.add_node(i, areaName=str(data0[k][0]), numberOfCrimes=str(data0[k][1]),
               D=random.randint(10,20), f=1)
    i += 1

#nodes with f=0 refers to Police_dept
for k in data0:
    G.add_node(i, numberOfD=str(data0[k][1]), f=0)
    i += 1

#I simply calculate random distance but this is not the case
distances = {}
for i in G.nodes():
    if G.node[i]['f'] == 1:
        for j in G.nodes():
            if G.node[j]['f'] == 0:
                distances[i,j] = random.randint(i,j)

有没有一个解决方案来替换我的distances和欧几里德距离,为每对区域计算得好 - > Police_Dept节点使用区域和部门的随机顺序(位置),比如在现实生活中?

0 个答案:

没有答案