Home | Trees | Indices | Help |
---|
|
Base class for graphs.
Create an empty graph structure (a "null graph") with zero nodes and zero edges.
>>> from networkx import * >>> G=Graph()
G can be grown in several ways. By adding one node at a time:
>>> G.add_node(1)
by adding a list of nodes:
>>> G.add_nodes_from([2,3])
by using an iterator:
>>> G.add_nodes_from(xrange(100,110))
or by adding any container of nodes
>>> H=path_graph(10) >>> G.add_nodes_from(H)
H can be another graph, or dict, or set, or even a file. Any hashable object (except None) can represent a node, e.g. a Graph, a customized node object, etc.
>>> G.add_node(H)
G can also be grown by adding one edge at a time:
>>> G.add_edge( (1,2) )
by adding a list of edges:
>>> G.add_edges_from([(1,2),(1,3)])
or by adding any ebunch of edges (see above definition of an ebunch):
>>> G.add_edges_from(H.edges())
There are no complaints when adding existing nodes or edges:
>>> G=Graph() >>> G.add_edge([(1,2),(1,3)])
will add new nodes as required.
Author: Aric Hagberg (hagberg@lanl.gov) Pieter Swart (swart@lanl.gov) Dan Schult(dschult@colgate.edu)
|
|||
Graph Graph is a simple graph without any multiple (parallel) edges or self-loops. |
|
|||
|
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0beta1 on Sun Aug 17 12:04:44 2008 | http://epydoc.sourceforge.net |