Warning

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

set_node_attributes

set_node_attributes(G, name, values)[source]

Set node attributes from dictionary of nodes and values

Parameters :

G : NetworkX Graph

name : string

Attribute name

values: dict

Dictionary of attribute values keyed by node. If \(values\) is not a dictionary, then it is treated as a single attribute value that is then applied to every node in \(G\).

Examples

>>> G = nx.path_graph(3)
>>> bb = nx.betweenness_centrality(G)
>>> nx.set_node_attributes(G, 'betweenness', bb)
>>> G.node[1]['betweenness']
1.0