如何在Python中制作有向图的深层副本? python中是否有任何现有的模块来处理图结构?每个节点都有一个data
字段和一个neighbors
字段,它是list
存储对相邻节点的引用。
答案 0 :(得分:0)
import networkx as nx
G1 = nx.Graph()
G1.add_edge(1, 2)
G2 = G1.copy() # makes a deep copy of G1 into G2
G2.add_edge(1, 3)
print G1.nodes() # prints [1, 2]
print G2.nodes() # prints [1, 2, 3]
您可以在此处找到更多信息:https://networkx.github.io/