I have worked with networkx
and am trying graph-tool
for potentially better performance. Working through the documentation I wish to create edges with properties. In networkx
I can do something like this for some graph G
:
G.add_edge(vertex_1, vertex_2, attr_dict={python dict of 'property: value'})
I wanted to do the same in graph-tool
. From the docs I tried the example with a slight change in that one of the properties in a python dict instead of an int:
edge_list = [(0, 1, .3, {'name':'hello'}), (2, 3, .1, {'name':'good'}), (2, 0, .4, {'name':'by'})]
g = gt.Graph()
eweight = g.new_ep("double")
elayer = g.new_ep("object")
g.add_edge_list(edge_list, eprops=[eweight, elayer])
print(eweight.a)
print(elayer.a)
g.get_edges()
OUTPUT:
[0.3 0.1 0.4]
None
array([[0, 1],
[2, 3],
[2, 0]])
I can see that the edges were entered correctly why is 'None' returned for the 'elayer' property?
UPDATE:
I have looked at the Property Map
docs and the example there looks like this:
eprop_dict = g.new_edge_property("object") # Arbitrary Python object.
e = g.edges().next()
eprop_dict[e] = {"foo": "bar", "gnu": 42} # In this case, a dict.
Also had a look at the source code.