gpt4 book ai didi

python - NetworkX:检查两个图是否具有相同的形状和相同的节点属性

转载 作者:太空宇宙 更新时间:2023-11-03 20:32:32 25 4
gpt4 key购买 nike

如果我有两个具有颜色属性的图表:

dags如何检查两个图形是否具有相同的形状,并且相同的颜色相互连接?节点号并不重要。

最佳答案

您需要使用Graph Isomorphism这在 NetworkX 中可用。您可以查看here .

这是来自 is_isomorphic 文档的官方示例。您可以查看here .

import networkx.algorithms.isomorphism as iso
import netoworkx as nx

G1 = nx.DiGraph()
G2 = nx.DiGraph()
nx.add_path(G1, [1,2,3,4], weight=1)
nx.add_path(G2, [10,20,30,40], weight=2)

# This will be used for attribute matching
em = iso.numerical_edge_match('weight', 1)

print(nx.is_isomorphic(G1, G2)) # no weights considered
#Output: True

print(nx.is_isomorphic(G1, G2, edge_match=em)) # match weights
# Output : False

关于python - NetworkX:检查两个图是否具有相同的形状和相同的节点属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57397431/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com