Filtering a subgraph in graph-tool
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Quirky Dreamscape Looping
--
Chapters
00:00 Question
01:35 Accepted answer (Score 7)
02:09 Thank you
--
Full question
https://stackoverflow.com/questions/3706...
Question links:
[page on PropertyMaps]: https://graph-tool.skewed.de/static/doc/...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #graphtool
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Quirky Dreamscape Looping
--
Chapters
00:00 Question
01:35 Accepted answer (Score 7)
02:09 Thank you
--
Full question
https://stackoverflow.com/questions/3706...
Question links:
[page on PropertyMaps]: https://graph-tool.skewed.de/static/doc/...
--
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)]