首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LightGraphs - Julia中的子图

LightGraphs - Julia中的子图
EN

Stack Overflow用户
提问于 2020-12-09 23:32:34
回答 1查看 163关注 0票数 1

假设我有一个有10^4个节点的大型网络。然后我想分析与随机节点相关联的邻居,比如节点10。我可以通过查看邻接矩阵的第10行条目来查看哪些节点连接到该节点,然后如果我想查看这些邻居的邻居(第二个shell),则可以重复此操作,依此类推。

有没有一种有效的方法来做到这一点--或者甚至是一种低效但比从头开始编写整个事情更好的方法?我实际拥有的网络是一个随机规则图,我对大型网络的树状本地结构很感兴趣。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-10 01:09:11

如果我理解您的用例,有一个很好的方法可以做到这一点:egonet函数。你给它一个图,一个起始顶点和跳数,它将返回从顶点开始的图的导出子图,直到跳数。这里是文档字符串:

代码语言:javascript
复制
  egonet(g, v, d, distmx=weights(g))

  Return the subgraph of g induced by the neighbors of v up to distance d, using weights (optionally) provided by distmx. This is equivalent to
  induced_subgraph(g, neighborhood(g, v, d, dir=dir))[1].

  Optional Arguments
  ––––––––––––––––––––

    •    dir=:out: if g is directed, this argument specifies the edge direction

  with respect to v (i.e. :in or :out).

编辑后添加:如果你只需要顶点索引,那么neighborhood()就是你想要的:

代码语言:javascript
复制
neighborhood(g, v, d, distmx=weights(g))                                                                                                            
                                                                                                                                                      
  Return a vector of each vertex in g at a geodesic distance less than or equal to d, where distances may be specified by distmx.                     
                                                                                                                                                      
  Optional Arguments                                                                                                                                  
  ––––––––––––––––––––                                                                                                                                
                                                                                                                                                      
    •    dir=:out: If g is directed, this argument specifies the edge direction                                                                       
                                                                                                                                                      
  with respect to v of the edges to be considered. Possible values: :in or :out.                             
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65219848

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档