Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查找不具有edge networkx python的节点对_Python_Nodes_Networkx_Graph Theory - Fatal编程技术网

查找不具有edge networkx python的节点对

查找不具有edge networkx python的节点对,python,nodes,networkx,graph-theory,Python,Nodes,Networkx,Graph Theory,我想找到所有可能的节点对,这些节点对没有连接它们的边,然后检查这些节点对在另一个图中是否有边。有什么建议吗?如果您不关心性能,那么您可以尝试: g1Edges = Graph1.edges() notG1Edges = set() for a in Graph1.nodes(): for b in Graph1.nodes(): if a != b and (a,b) not in g1Edges: notG1Edges.add( (a, b) )

我想找到所有可能的节点对,这些节点对没有连接它们的边,然后检查这些节点对在另一个图中是否有边。有什么建议吗?

如果您不关心性能,那么您可以尝试:

g1Edges = Graph1.edges()
notG1Edges = set()
for a in Graph1.nodes():
    for b in Graph1.nodes():
        if a != b and (a,b) not in g1Edges:
            notG1Edges.add( (a, b) )
# print edges missed in Graph1 and Graph2
print notG1Edges.difference( Graph2.edges_iter() )
注1:这适用于有向图


注2:如果要查找Graph2中不存在于Graph1中的边子集,则假设最好对Graph2中的边进行操作,因此。。。到目前为止你得到了什么?不,不是家庭作业…正在做一个研究项目:)你能帮我一下吗,因为我正在做的图表没有指向。。。我想得到有边的图的补码。。。直觉上,我会在所有没有边缘的节点中获得边缘…但似乎无法获得正确的代码…可以帮我解决这个问题…发布一些代码,可能有人会告诉你为什么它不起作用。