This is a ridiculously basic question about graph-tool which should be trivial to figure out how to solve using the documentation, but I'm spinning in circles. I don't doubt that documentation comprehensive, but it certainly isn't making this easy.
GOAL: Given a graph G, extract the induced subgraph based on a list of vertices of G.
I know I should be doing this with a
You are right. You have to use
GraphView. In the following example a induced subgraph with vertices 0, 1, 3 are created from a complete graph with 5 vertices
from graph_tool import GraphView, generation g = generation.complete_graph(5) # select some vertices vfilt = g.new_vertex_property('bool'); vfilt = True vfilt = True vfilt = True sub = GraphView(g, vfilt) print [(g.vertex_index[e.source()], g.vertex_index[e.target()]) for e in sub.edges()]
[(0, 1), (0, 3), (1, 3)]