Graph-Tool:Edge属性无法将其设置为type'对象'
我已经使用networkx
,并且正在尝试Graph-tool
,以获得更好的性能。我希望通过文档来创建具有属性的边缘。在networkx
中,我可以为某些图形G
:
G.add_edge(vertex_1, vertex_2, attr_dict={python dict of 'property: value'})
我想在Graph-tool
中执行相同的操作。来自我尝试了一个示例,并进行了略有更改,该示例是python dict 而不是 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]])
我可以看到正确输入了边缘,为什么是'没有人返回“ Elayer”属性?
更新:
我已经查看了属性映射
docs ,那里的示例看起来像这样:
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.
还可以查看源代码。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让我们看一下文档告诉我们的内容:
这给了我们:
现在让我们查看
propertymap.get_array的文档
:上面的注释回答您的问题:数组接口仅适用于标量类型,而不是标量任意python对象。
对于任意类型,使用基于边缘描述符的标准接口仍然可以进行属性的分配和查找,例如:
它为您提供
Let's look at what the documentation tells us:
This gives us:
Now let us look at the documentation of
PropertyMap.get_array
:The note above answers your question: the array interface is provided only for scalar types, not arbitrary python objects.
For arbitrary types, assignment and lookup of properties is still possible using the standard interface based on edge descriptors, e.g.:
which gives you