NetworkX

Previous topic

networkx.MultiGraph.add_node

Next topic

networkx.MultiGraph.remove_node

networkx.MultiGraph.add_nodes_from

MultiGraph.add_nodes_from(nodes, **attr)

Add multiple nodes.

Parameters:

nodes : iterable container

A container of nodes (list, dict, set, etc.). The container will be iterated through once.

attr : keyword arguments, optional (default= no attributes)

Update attributes for all nodes in nodes.

See also

add_node

Examples

>>> G = nx.Graph()   # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G.add_nodes_from('Hello')
>>> K3 = nx.Graph([(0,1),(1,2),(2,0)])
>>> G.add_nodes_from(K3)
>>> sorted(G.nodes())
[0, 1, 2, 'H', 'e', 'l', 'o']

Use keywords to update specific node attributes for every node.

>>> G.add_nodes_from([1,2], size=10)
>>> G.add_nodes_from([3,4], weight=0.4)