How to get values from specific node attributes in NetworkX with Python

后端 未结 1 753
花落未央
花落未央 2021-01-21 16:55

I\'m working on a group project and we need to create a list of all the values from a specific node attribute in the graph we are working on. Each node has 6 attributes, we jus

相关标签:
1条回答
  • 2021-01-21 17:28

    Your code won't run without more info. I think you want something like the function networkx.get_node_attributes():

    In [1]: import networkx as nx
    
    In [2]: G = nx.Graph()
    
    In [3]: G.add_node(1,profit=17)
    
    In [4]: G.add_node(2,profit=42)
    
    In [5]: a = nx.get_node_attributes(G,'profit')
    
    In [6]: a.items()
    Out[6]: [(1, 17), (2, 42)]
    
    0 讨论(0)
提交回复
热议问题