networknx python的子图函数

2024-09-30 20:29:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我想问一下是否有人可以帮助我理解这个python模块中的子图函数。E、 简单图上的g。子图函数在第1400行和第1458行之间。在

https://github.com/networkx/networkx/blob/e73face328281b9afe7eb848887f17d97be1709d/networkx/classes/graph.py#L1400-L1458


Tags: 模块函数pyhttpsnetworkxgithubcomblob
1条回答
网友
1楼 · 发布于 2024-09-30 20:29:09

这是该函数的一些伪代码。在

def get_subgraph(existing_graph, node_ids):
    get the nodes that correspond to the node_ids
    create a new graph, make sure it is the same type
    for each node in the list of chosen nodes:
        copy the node to the new graph, retaining its associated data
    get a lookup table of edges for the nodes in the new graph
    for each node in the new graph:
        get its neighbors from the old graph
        for each of the neighbors:
            if the neighbor is in the new graph:
                add the edge to the new graph (from both directions if needed)

相关问题 更多 >