1

我通过随机抽取生成了一个网络。现在,当我通过 LightGraphs.jl 绘制网络时,我还得到了未连接的节点:

但是,我希望从图中排除这些节点。这可能吗?

4

1 回答 1

0

是的,使用getindexorinduced_subgraph函数(我假设您要排除0-degree 节点):

julia> Random.seed!(123);

julia> g = erdos_renyi(10, 0.1)
{10, 7} undirected simple Int64 graph

julia> degree(g)
10-element Vector{Int64}:
 1
 4
 1
 1
 1
 2
 0
 2
 2
 0

julia> sg = g[findall(>(0), degree(g))]
{8, 7} undirected simple Int64 graph

julia> degree(sg)
8-element Vector{Int64}:
 1
 4
 1
 1
 1
 2
 2
 2

julia> sg2 = induced_subgraph(g, findall(>(0), degree(g)))
({8, 7} undirected simple Int64 graph, [1, 2, 3, 4, 5, 6, 8, 9])

julia> sg2[1] == sg
true

的好处induced_sugraph是它还返回一个向量,将新顶点映射到旧顶点。

于 2021-07-05T16:32:36.400 回答