
您要查找的函数是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。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)