我已经通过随机抽奖生成了一个网络。现在,当我通过LightGraphs.jl绘制网络图时,我还得到了未连接的节点:
但是,我希望从图中排除这些节点。这个是可能的吗?
发布于 2021-07-06 00:32:36
可以,使用getindex或induced_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
trueinduced_sugraph的好处是它还返回一个将新顶点映射到旧顶点的向量。
https://stackoverflow.com/questions/68258981
复制相似问题