get_node_attributes#
- get_node_attributes(G, name, default=None)[source]#
Get node attributes from graph
- Parameters:
- GNetworkX Graph
- namestring
Attribute name
- default: object (default=None)
Default value of the node attribute if there is no value set for that node in graph. If
Nonethen nodes without this attribute are not included in the returned dict.
- Returns:
- Dictionary of attributes keyed by node.
Examples
>>> G = nx.Graph() >>> G.add_nodes_from([1, 2, 3], color="red") >>> color = nx.get_node_attributes(G, "color") >>> color[1] 'red' >>> G.add_node(4) >>> color = nx.get_node_attributes(G, "color", default="yellow") >>> color[4] 'yellow'