# Graphs into layers

Hi all,

If I have two graphs g and h with internal edge property maps, how can I make these the layers of a graph i?

g = Graph(directed=False)
g_weight = g.new_ep('int')
g_layer = g.new_ep('int')
g.add_edge_list([[0, 1, 2, 0], [2, 3, 2, 0]], eprops=[g_weight, g_layer])
g.edge_properties['weight'] = g_weight
g.edge_properties['layer'] = g_layer

h = Graph(directed=False)
h_weight = h.new_ep('int')
h_layer = h.new_ep('int')
h.add_edge_list([[1, 2, 1, 1]], eprops=[h_weight, h_layer])
h.edge_properties['weight'] = h_weight
h.edge_properties['layer'] = h_layer

This works but is not nice and gets lengthy when layers are many:

i = g.copy() # make deep copy
i.ep.weight.a[-h.num_edges():] = h.ep.weight.a # manually add the edge weight
i.ep.layer.a[-h.num_edges():] = h.ep.weight.a # manually add the edge layer

Is there a better way?

I'm using gt 2.29 from conda-ostrokach.

Many thanks

Haiko

attachment.html (3.5 KB)

Is there a better way?

Yes, take a look at the graph_union() function, with joins two graphs
into one. If you pass it an 'intersection' parameter, it maps nodes of
one graph into the other, which allows you to join only the edge lists.

I’m using gt 2.29 from conda-ostrokach.