python graph-tool access vertex properties

倖福魔咒の 提交于 2019-12-06 04:13:21

The function you are looking for is find_vertex():

https://graph-tool.skewed.de/static/doc/util.html#graph_tool.util.find_vertex

It is important to realize that graph-tool achieves its speed by off-loading performance-sensitive loops from Python to C++. So whenever you iterate through the vertices, like you did in your code, you lose any advantage.

Note also that, although find_vertex() is implemented in C++, and hence many times faster than the equivalent in pure Python, it is still an O(N) operation. For large graphs, you are better off creating a good old python dictionary that maps property values to vertices, which has an O(1) cost for lookup.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!