summaryrefslogtreecommitdiff
path: root/networkx/classes/function.py
diff options
context:
space:
mode:
authoraric <none@none>2010-03-23 12:49:00 +0000
committeraric <none@none>2010-03-23 12:49:00 +0000
commit85c83321deb4cd2af90278160097260ae1aa21af (patch)
tree1352427b6aa6172a2711d64917e209954bcba4ba /networkx/classes/function.py
parent94c55c85352160a0b4bd59eb2e59382bd212f186 (diff)
downloadnetworkx-85c83321deb4cd2af90278160097260ae1aa21af.tar.gz
Move subgraph and create_empty copy to function.py
--HG-- extra : convert_revision : svn%3A3ed01bd8-26fb-0310-9e4c-ca1a4053419f/networkx/trunk%401571
Diffstat (limited to 'networkx/classes/function.py')
-rw-r--r--networkx/classes/function.py33
1 files changed, 29 insertions, 4 deletions
diff --git a/networkx/classes/function.py b/networkx/classes/function.py
index 09f30695..8d69352a 100644
--- a/networkx/classes/function.py
+++ b/networkx/classes/function.py
@@ -1,9 +1,11 @@
"""
-Functional interface to graph properties.
+Functional interface to graph methods and assorted utilities.
"""
-__author__ = """Aric Hagberg (hagberg@lanl.gov)\nPieter Swart (swart@lanl.gov)\nDan Schult(dschult@colgate.edu)"""
-# Copyright (C) 2004-2008 by
+__author__ = """\n""".join('Aric Hagberg (hagberg@lanl.gov)',
+ 'Pieter Swart (swart@lanl.gov)',
+ 'Dan Schult(dschult@colgate.edu)')
+# Copyright (C) 2004-2010 by
# Aric Hagberg <hagberg@lanl.gov>
# Dan Schult <dschult@colgate.edu>
# Pieter Swart <swart@lanl.gov>
@@ -17,7 +19,7 @@ import networkx
__all__ = ['nodes', 'edges', 'degree', 'degree_histogram', 'neighbors',
'number_of_nodes', 'number_of_edges', 'density',
'nodes_iter', 'edges_iter', 'is_directed','info',
- 'freeze','is_frozen']
+ 'freeze','is_frozen','subgraph','create_empty_copy']
def nodes(G):
"""Return a copy of the graph nodes in a list."""
@@ -190,3 +192,26 @@ def is_frozen(G):
return G.frozen
except AttributeError:
return False
+
+def subgraph(G, nbunch):
+ """Return the subgraph induced on nodes in nbunch.
+
+ Parameters
+ ----------
+ G : graph
+ A NetworkX graph
+
+ nbunch : list, iterable
+ 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. If nbunch is None, return all edges data in the graph.
+ Nodes in nbunch that are not in the graph will be (quietly)
+ ignored.
+
+ Notes
+ -----
+ subgraph(G) calls G.subgraph()
+
+ """
+ return G.subgraph(nbunch)