python networkx remove nodes and edges with some condition

前端 未结 3 714
-上瘾入骨i
-上瘾入骨i 2021-02-05 22:56

In the python library networkx I would like to remove the nodes and edges of a graph which have some property. For example, suppose I wanted to remove all nodes and edges where

3条回答
  •  野性不改
    2021-02-05 23:07

    Note that in Aric's for networkx==2.2, you need to wrap G.degree() in a dictionary because the networkx view object doesn't have an items method. This line would be:

    [node for node,degree in dict(G.degree()).items() if degree > 2]
    

提交回复
热议问题