Best practices for Querying graphs by edge and node attributes in NetworkX

前端 未结 3 735
野性不改
野性不改 2020-12-04 11:38

Using NetworkX, and new to the library, for a social network analysis query. By Query, I mean select/create subgraphs by attributes of both edges nodes where the edges creat

3条回答
  •  猫巷女王i
    2020-12-04 12:22

    Building on @Aric's answer, you can find red fish like this:

    red_fish = set(n for u,v,d in G.edges_iter(data=True)
                   if d['color']=='red'
                   for n in (u, v)
                   if G.node[n]['label']=='fish')
    
    print(red_fish)
    # set([2])
    

提交回复
热议问题