### Navigation

- index
- modules |
- modules |
- FNSS 0.6.0 documentation »

# fnss.topologies.topology.Topology.subgraph

`Topology.``subgraph`(nbunch)

  Return the subgraph induced on nodes in nbunch.

  The induced subgraph of the graph contains the nodes in nbunch and the edges between those nodes.

  Parameters: | nbunch : list, iterable A container of nodes which will be iterated through once.
  Returns: | topology : Topology A subgraph of the graph with the same edge attributes.

  Notes

  The graph, edge or node attributes just point to the original graph. So changes to the node or edge structure will not be reflected in the original graph while changes to the attributes will.

  To create a subgraph with its own copy of the edge/node attributes use: Topology(G.subgraph(nbunch))

  If edge attributes are containers, a deep copy can be obtained using: G.subgraph(nbunch).copy()

  For an inplace reduction of a graph to a subgraph you can remove nodes: G.remove_nodes_from([ n in G if n not in set(nbunch)])

  Examples

      >>> topo = Topology()
      >>> topo.add_path([0,1,2,3])
      >>> topo2 = topo.subgraph([0,1,2])
      >>> topo2.edges()
      [(0, 1), (1, 2)]

### Navigation

- index
- modules |
- modules |
- FNSS 0.6.0 documentation »