我正在为Python使用NetworkX图形库。在我的程序中,我想把我的nodeid“合并”成一系列的数字。这是我天真的做法:
start = 1 # could be anything
for i, n in enumerate(g.nodes()):
if i+start == n:
continue
g.add_node(i+start, attr_dict=g.node[n])
g.add_edges_from([(i+start, v, g[n][v]) for v in g.neighbors(n)])
g.remove_node(n)
有没有比邻里抄得更快的?例如,我尝试了g[i+start] = g[n]
,但这是禁止的。在
谢谢!在
如果您的兴趣仍然相关,有一个^{} ,它需要一个映射字典。在
这样行吗?在
http://networkx.github.io/documentation/latest/reference/generated/networkx.relabel.convert_node_labels_to_integers.html
退货:
^{pr2}$现在:
退货:
相关问题 更多 >
编程相关推荐