在networkX python中,是否可以添加具有相同ID的相同内容? [英] In networkX python , is it possible to add the same with same ID ?
本文介绍了在networkX python中,是否可以添加具有相同ID的相同内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果添加了重复的节点(相同的id,相同的其他属性),networkX将如何处理?谢谢
What will networkX do if the duplicated nodes (same id , same other attributes )are added? thanks
推荐答案
如果使用具有重复属性的重复ID添加节点,则该节点将被忽略.但是,如果属性不同,则将更改它们.例如:
If you add a node using a duplicate id with duplicate attributes it will be ignored. However if the attributes are different they will be changed. For example:
>>> import networkx as nx
>>> G = nx.Graph()
>>> G.add_node(1)
>>> G.node[1]
{}
>>> G.add_node(1,name='firstNode')
>>> G.node[1]
{'name': 'firstNode'}
>>> G.add_node(1,name='changed')
>>> G.node[1]
{'name': 'changed'}
>>> G.add_node(1,name='changed',attribute='new')
>>> G.node[1]
{'attribute': 'new', 'name': 'changed'}
>>> G.add_node(1,name='changed',attribute='new')
>>> G.node[1]
{'attribute': 'new', 'name': 'changed'}
>>> G.add_node(1)
>>> G.node[1]
{'attribute': 'new', 'name': 'changed'}
>>> nx.nodes(G)
[1]
这篇关于在networkX python中,是否可以添加具有相同ID的相同内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文