隔离 connected_components
Isolate connected_components
我有以下 networkx 图摘录:
执行了以下函数来探索连接组件的结构,因为我有一个包含大量奇异连接的稀疏网络:
nx.number_connected_components(G)
>>> 702
list(nx.connected_components(G))
>>> [{120930, 172034},
{118787, 173867, 176202},
{50376, 151561},
...]
问题:如何将我的整个图形可视化限制为connected_components,具有等于或多于三个个节点?
我们可以创建一个包含具有等于或多于三个节点的组件的子图:
s = G.subgraph(
set.union(
*filter(lambda x: len(x) >= 3, nx.connected_components(G))
)
)
现在你只需要可视化这个子图s
。
我们可能需要制作副本而不是 SubGraph
视图,在这种情况下,s = s.copy()
将从子图中制作副本。
graphs = list(nx.connected_component_subgraphs(G))
list_subgraphs=[items for i in graphs for items in i if len(i)>=3]
F=G.subgraph(list_subgraphs)
创建一个包含大于 3 个节点的组件的子图的平面列表!
我有以下 networkx 图摘录:
执行了以下函数来探索连接组件的结构,因为我有一个包含大量奇异连接的稀疏网络:
nx.number_connected_components(G)
>>> 702
list(nx.connected_components(G))
>>> [{120930, 172034},
{118787, 173867, 176202},
{50376, 151561},
...]
问题:如何将我的整个图形可视化限制为connected_components,具有等于或多于三个个节点?
我们可以创建一个包含具有等于或多于三个节点的组件的子图:
s = G.subgraph(
set.union(
*filter(lambda x: len(x) >= 3, nx.connected_components(G))
)
)
现在你只需要可视化这个子图s
。
我们可能需要制作副本而不是 SubGraph
视图,在这种情况下,s = s.copy()
将从子图中制作副本。
graphs = list(nx.connected_component_subgraphs(G))
list_subgraphs=[items for i in graphs for items in i if len(i)>=3]
F=G.subgraph(list_subgraphs)
创建一个包含大于 3 个节点的组件的子图的平面列表!