栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

合并(加入)networkx图

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

合并(加入)networkx图

您要查找的函数是compose,该函数将生成一个图形,其中包含两个图形中的所有边缘和所有节点。如果两个图都有一个具有相同名称的节点,则单个副本将最终出现在新图中。如果两者都存在相同的边,则类似。这是一个示例,其中包括edge
/ node属性:

import networkx as nxG=nx.Graph()G.add_node(1, weight = 2)G.add_node(2, weight = 3)G.add_edge(1,2, flux = 5)G.add_edge(2,4)H=nx.Graph()H.add_node(1, weight = 4)H.add_edge(1,2, flux = 10)H.add_edge(1,3)F = nx.compose(G,H)#F has all nodes & edges of both graphs, including attributes#Where the attributes conflict, it uses the attributes of H.G.nodes(data=True)> NodeDataView({1: {'weight': 2}, 2: {'weight': 3}, 4: {}})H.nodes(data=True)> NodeDataView({1: {'weight': 4}, 2: {}, 3: {}})F.nodes(data=True)> NodeDataView({1: {'weight': 4}, 2: {'weight': 3}, 4: {}, 3: {}})G.edges(data=True)> EdgeDataView([(1, 2, {'flux': 5}), (2, 4, {})])H.edges(data=True)> EdgeDataView([(1, 2, {'flux': 10}), (1, 3, {})])F.edges(data=True)EdgeDataView([(1, 2, {'flux': 10}), (1, 3, {}), (2, 4, {})])

这些保留属性,但是显然如果发生冲突,则不可能。

H
优先级的属性。

还有其他选择可做对称差异,相交,…

如果您有多个图形要连接在一起,则可以使用

compose_all
,只需将for循环环绕
compose



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/517129.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号