【发布时间】:2023-02-25 14:51:34
【问题描述】:
我构建了一个包含以下详细信息的图表。我感到困惑的是,为什么在删除图形的一条边之后,当我尝试打印所有边数据时它仍然存在?我做错什么了吗?
import networkx as nx
G = nx.MultiGraph()
G.add_edge(17, 12, nm=5, asset="a12")
G.add_edge(14, 13, nm=15, asset="a13")
G.add_edge(17, 13, nm=5, asset="a14")
G.add_edge(27, 110, nm=15, asset="a15")
G.add_edge(27, 110, nm=5, asset="a19")
G.add_edge(27, 280, nm=5, asset="a19")
# remove asset a15
for a, b, attributes in G.edges(data=True):
if attributes["asset"]=="a15":
lst=[(a, b)]
G.remove_edges_from(lst)
#print the current edges in the graph
for cc in nx.connected_components(G):
print("asset", list(nx.get_edge_attributes(G.subgraph(cc), "asset").values()))
输出:
asset ['a12', 'a14', 'a13']
asset ['a19', 'a15']
为什么'a15' 仍然存在?
【问题讨论】: