在NetworkX中测试图是否相等 [英] Test graph equality in NetworkX

查看:391
本文介绍了在NetworkX中测试图是否相等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

测试两个NetworkX图是否相同(即相同的节点集,每个节点上的相同节点属性,相同的边集和相同的边线属性)的最有效方法是什么?假设我们知道两个图是同一类.

What's the most efficient way to test if two NetworkX graphs are identical (i.e. same set of nodes, same node attributes on each node, same set of edges and same edge attributes on each edge)? Suppose that we know the two graphs are of the same class.

感谢您的友好回答.

推荐答案

NetworkX中有一个名为 is_isomorphic()

There's a function in NetworkX called is_isomorphic()

以下是该页面的示例:

>>> import networkx.algorithms.isomorphism as iso
>>> G1 = nx.DiGraph()
>>> G2 = nx.DiGraph()
>>> G1.add_path([1,2,3,4],weight=1)
>>> G2.add_path([10,20,30,40],weight=2)
>>> em = iso.numerical_edge_match('weight', 1)
>>> nx.is_isomorphic(G1, G2)  # no weights considered
True
>>> nx.is_isomorphic(G1, G2, edge_match=em) # match weights
False

这篇关于在NetworkX中测试图是否相等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆