To map the index of an unfiltered graph to the index of a filtered graph in Python's graphtool library, you can use the 'mapvertex_index' function.
Here's an example code snippet:
import graph_tool.all as gt
# load your unfiltered graph
ug = gt.load_graph("unfiltered_graph.gt")
# create a filter
vfilt = gt.label_largest_component(ug)
# apply filter to unfiltered graph
fg = gt.GraphView(ug, vfilt)
# map the vertex indices from unfiltered graph to filtered graph
vmap = gt.graph_tool.util.map_vertex_index(ug, fg)
# get the index of a vertex in the unfiltered graph
u_index = 10
# map the index of the vertex in the unfiltered graph to filtered graph
f_index = vmap[u_index]
print("Index of vertex %d in the unfiltered graph: %d" % (u_index, f_index))
Note that in the example, we first load our unfiltered graph and create a filter using 'labellargestcomponent'. We then apply this filter to create a filtered graph 'fg'. We then use the 'mapvertexindex' function to get a mapping from the vertex indices in the unfiltered graph to vertex indices in the filtered graph. Finally, we use this mapping to get the filtered graph index of a vertex with a particular index in the unfiltered graph.
Asked: 2021-10-23 11:00:00 +0000
Seen: 7 times
Last updated: Mar 30 '22