Package networkx :: Module tree :: Class Tree
[hide private]
[frames] | no frames]

Class Tree

source code

 object --+    
          |    
graph.Graph --+
              |
             Tree
Known Subclasses:
DirectedForest, DirectedTree, Forest, RootedTree

A free (unrooted) tree.

Instance Methods [hide private]
 
__init__(self, data=None, **kwds)
Initialize Graph.
source code
 
add_node(self, n)
Add a single node n to the graph.
source code
 
add_nodes_from(self, nbunch)
Add multiple nodes to the graph.
source code
 
delete_node(self, n)
Delete node n from graph.
source code
 
delete_nodes_from(self, nbunch)
Remove nodes in nlist from graph.
source code
 
add_edge(self, u, v=None)
Add a single edge (u,v) to the graph.
source code
 
add_edges_from(self, ebunch)
Add all the edges in ebunch to the graph.
source code
 
delete_edge(self, u, v=None)
Delete the single edge (u,v).
source code
 
delete_edges_from(self, ebunch)
Delete the edges in ebunch from the graph.
source code
 
add_leaf(self, u, v=None) source code
 
delete_leaf(self, u, v=None) source code
 
add_leaves_from(self, ebunch) source code
 
delete_leaves_from(self, ebunch) source code
 
union_sub(self, T1, **kwds)
Polymorphic helper method for Graph.union().
source code
 
union_sub_tree_helper(self, T1, parent, grandparent=None) source code

Inherited from graph.Graph: __contains__, __getitem__, __iter__, __len__, __str__, add_cycle, add_path, clear, copy, degree, degree_iter, edge_boundary, edges, edges_iter, get_edge, has_edge, has_neighbor, has_node, info, is_directed, neighbors, neighbors_iter, node_boundary, nodes, nodes_iter, number_of_edges, number_of_nodes, order, prepare_nbunch, size, subgraph, to_directed, to_undirected

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, data=None, **kwds)
(Constructor)

source code 

Initialize Graph.

>>> G=Graph(name="empty")

creates empty graph G with G.name="empty"

Overrides: graph.Graph.__init__
(inherited documentation)

add_node(self, n)

source code 

Add a single node n to the graph.

The node n can be any hashable object except None.

A hashable object is one that can be used as a key in a Python dictionary. This includes strings, numbers, tuples of strings and numbers, etc. On many platforms this also includes mutables such as Graphs e.g., though one should be careful the hash doesn't change on mutables.

Example:

>>> from networkx import *
>>> G=Graph()
>>> K3=complete_graph(3)
>>> G.add_node(1)
>>> G.add_node('Hello')
>>> G.add_node(K3)
>>> G.number_of_nodes()
3
Overrides: graph.Graph.add_node
(inherited documentation)

add_nodes_from(self, nbunch)

source code 

Add multiple nodes to the graph.

nlist: A container of nodes that will be iterated through once (thus it should be an iterator or be iterable). Each element of the container should be a valid node type: any hashable type except None. See add_node for details.

Examples:

>>> from networkx import *
>>> G=Graph()
>>> K3=complete_graph(3)
>>> G.add_nodes_from('Hello')
>>> G.add_nodes_from(K3)
>>> sorted(G.nodes())
[0, 1, 2, 'H', 'e', 'l', 'o']
Overrides: graph.Graph.add_nodes_from
(inherited documentation)

delete_node(self, n)

source code 
Delete node n from graph. Attempting to delete a non-existent node will raise an exception.
Overrides: graph.Graph.delete_node
(inherited documentation)

delete_nodes_from(self, nbunch)

source code 

Remove nodes in nlist from graph.

nlist: an iterable or iterator containing valid node names.

Attempting to delete a non-existent node will raise an exception. This could mean some nodes got deleted and other valid nodes did not.

Overrides: graph.Graph.delete_nodes_from
(inherited documentation)

add_edge(self, u, v=None)

source code 

Add a single edge (u,v) to the graph.

>> G.add_edge(u,v) and >>> G.add_edge( (u,v) ) are equivalent forms of adding a single edge between nodes u and v. The nodes u and v will be automatically added if not already in the graph. They must be a hashable (except None) Python object.

The following examples all add the edge (1,2) to graph G.

>>> G=Graph()
>>> G.add_edge( 1, 2 )          # explicit two node form
>>> G.add_edge( (1,2) )         # single edge as tuple of two nodes
>>> G.add_edges_from( [(1,2)] ) # add edges from iterable container
Overrides: graph.Graph.add_edge
(inherited documentation)

add_edges_from(self, ebunch)

source code 

Add all the edges in ebunch to the graph.

ebunch: Container of 2-tuples (u,v). The container must be iterable or an iterator. It is iterated over once. Adding the same edge twice has no effect and does not raise an exception.

Overrides: graph.Graph.add_edges_from
(inherited documentation)

delete_edge(self, u, v=None)

source code 

Delete the single edge (u,v).

Can be used in two basic forms: >>> G.delete_edge(u,v) and >> G.delete_edge( (u,v) ) are equivalent ways of deleting a single edge between nodes u and v.

Return without complaining if the nodes or the edge do not exist.

Overrides: graph.Graph.delete_edge
(inherited documentation)

delete_edges_from(self, ebunch)

source code 

Delete the edges in ebunch from the graph.

ebunch: an iterator or iterable of 2-tuples (u,v).

Edges that are not in the graph are ignored.

Overrides: graph.Graph.delete_edges_from
(inherited documentation)

union_sub(self, T1, **kwds)

source code 

Polymorphic helper method for Graph.union().

Required keywords: v_from and v_to, where v_from is the node in self to which v_to should be attached as child.