Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

networkx.classes.function.get_node_attributes

get_node_attributes(G, name)[source]

Get node attributes from graph

Parameters
  • G (NetworkX Graph)

  • name (string) – Attribute name

Returns

Return type

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'