Am 29.08.19 um 15:43 schrieb Lietz, Haiko:
Hi Alexandre,
Thx for your reply! Indeed, your and my following optimizations are not gt-specific. I’m now here:
# set layer to be drawn
layer = 0
# create graph view
v_filter = edge_list.groupby('layer')[['i', 'j']].apply(lambda x: set(x.values.flatten())).to_dict() # create dictionary with vertices in a layer
vp_filter = g.new_vp('bool')
vp_filter.a[list(v_filter[layer])] = True
ep_filter = g.new_ep('bool')
ep_filter.a[g.ep['layer'].a == layer] = True # replaces my or Alexandre's loop
g_filter = GraphView(g, vfilt=vp_filter, efilt=ep_filter)
# draw filtered graph
graph_draw(g_filter, edge_color=g.ep.layer)
This is already rather short and nice. Still, I'm wondering if there’s a way that is more gt-esque.
You seem to be insisting on keeping an external list of edges for each layer, and most of the complication stems from having to project from this external data structure. By far the simplest approach is to have a single edge property map with the layer labels, and use that to do the filtering, i.e. elayer = g.new_ep("int") # populate g and elayer g_l = GraphView(g, efilt=elayer.fa == l) # layer l Best, Tiago -- Tiago de Paula Peixoto <tiago@skewed.de>