The Python Oracle

Filtering a subgraph in graph-tool

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Droplet of life

--

Chapters
00:00 Filtering A Subgraph In Graph-Tool
01:06 Accepted Answer Score 8
01:32 Thank you

--

Full question
https://stackoverflow.com/questions/3706...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #graphtool

#avk47



ACCEPTED ANSWER

Score 8


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[0] = True
vfilt[1] = True
vfilt[3] = True

sub = GraphView(g, vfilt)

print [(g.vertex_index[e.source()], g.vertex_index[e.target()])
           for e in sub.edges()]

Output

[(0, 1), (0, 3), (1, 3)]