[英]Difference between two NetworkX graphs with different node sets
I want the difference G1-G2 giving an output of edges which exist in G1, but not in G2. 我希望差G1-G2给出G1中存在的边的输出,但G2中不存在。 The difference
function in NetworkX allows this difference only when G1 and G2 have same node sets. 仅当G1和G2具有相同的节点集时,NetworkX中的difference
功能才允许这种差异。
My example: G1.edges= EdgeView([(0, 1), (1, 2), (1, 3), (1, 18))
我的例子:G1.edges = EdgeView([(0, 1), (1, 2), (1, 3), (1, 18))
G2.edges= EdgeView([(0, 1), (1, 2), (1, 3), (2, 22)])
G2.edges = EdgeView([(0, 1), (1, 2), (1, 3), (2, 22)])
Desired output is (1,18)
所需的输出是(1,18)
The EdgeView class defines set operations on edges. EdgeView类在边缘上定义设置操作。
Thus, you may simply use: 因此,您可以简单地使用:
G1.edges() - G2.edges()
Example: 例:
>>> G2.edges()
EdgeView([(0, 1), (1, 2), (1, 3), (2, 22)])
>>> G1.edges()
EdgeView([(0, 1), (1, 2), (1, 3), (1, 18)])
>>> G1.edges() - G2.edges()
{(1, 18)}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.