AP_Vehn
networkx 有没有办法找到离特定节点一定距离内的所有节点?如在,我指定一个节点和一个距离,并返回该距离内的所有节点。这是假设我为每条边添加了一个权重。
或者,有没有办法从特定节点找到指定度数内的所有节点?比如,与特定节点相距 2 度以内的所有节点是什么?度的意思,一个节点连接一个节点,一个节点连接一个节点。谢谢您的帮助!
里卡多·布科
您可以使用库的ego_graph
功能networkx
:
node = 3 # The center node
radius = 3 # Degrees of separation
new_graph = nx.generators.ego_graph(graph, node, radius=radius)
例如:
import networkx as nx
G = nx.gnm_random_graph(n=n, m=30, seed=1)
G = nx.generators.ego_graph(G, 0, radius=2)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
编辑于
我来说两句