Storing and Accessing node attributes python networkx

前端 未结 4 1626
天命终不由人
天命终不由人 2020-12-07 13:41

I have a network of nodes created using python networkx. i want to store information in nodes such that i can access the information later based on the node lab

4条回答
  •  有刺的猬
    2020-12-07 13:51

    As of networkx v2.0, you can use:

    import networkx as nx
    
    G = nx.Graph()
    G.add_node('abc', dob=1185, pob='usa', dayob='monday')
    nx.get_node_attributes(G, 'dob')
    > {'abc': 1185}
    

    You can access this dictionary as usual:

    {'abc': 1185}['abc']
    > 1185
    

提交回复
热议问题