graphscope.experimental.nx.Graph.add_nodes_from¶
-
Graph.
add_nodes_from
(nodes_for_adding, **attr)[source]¶ Add multiple nodes.
- Parameters
nodes_for_adding (iterable container) – A container of nodes (list, dict, set, etc.). OR A container of (node, attribute dict) tuples. Node attributes are updated using the attribute dict.
attr (keyword arguments, optional (default= no attributes)) – Update attributes for all nodes in nodes. Node attributes specified in nodes as a tuple take precedence over attributes specified via keyword arguments.
See also
Examples
>>> G = nx.Graph() # or DiGraph >>> G.add_nodes_from([1, 2, 3, 4, 5]) >>> G.number_of_nodes() 5
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)
Use (node, attrdict) tuples to update attributes for specific nodes.
>>> G.add_nodes_from([(1, dict(size=11)), (2, {'color':'blue'})]) >>> G.nodes[1]['size'] 11 >>> H = nx.Graph() >>> H.add_nodes_from(G.nodes(data=True)) >>> H.nodes[1]['size'] 11