Hi,
I would like to create a function which quickly exports a Graph to an edge list in Python. Bassically the opposite to the `Graph.add_edge_list` method. My current solution is:
edge_list = [ [int(e.source()), int(e.target())] for e in g.edges()]
As you can imagine this is very slow as the iteration is done in Python and not C++. Has anyone done this before, or knows how to do this at C++ speed?
Many thanks,
Josh Levy-Kramer Data Scientist @ Starcount
Hi,
You can use edge_endpoint_property: https://graph-tool.skewed.de/static/doc/graph_tool.html#graph_tool.edge_endp...
The example in that page is getting a numpy array of source vertices for all edges. It's very fast.
- Ilkka
On Tue, Mar 22, 2016 at 11:23 AM, Josh Levy-Kramer josh@starcount.com wrote:
Hi,
I would like to create a function which quickly exports a Graph to an edge list in Python. Bassically the opposite to the `Graph.add_edge_list` method. My current solution is:
edge_list = [ [int(e.source()), int(e.target())] for e in g.edges()]
As you can imagine this is very slow as the iteration is done in Python and not C++. Has anyone done this before, or knows how to do this at C++ speed?
Many thanks,
Josh Levy-Kramer Data Scientist @ Starcount
graph-tool mailing list graph-tool@skewed.de http://lists.skewed.de/mailman/listinfo/graph-tool
On 22.03.2016 09:19, Ilkka Rajala wrote:
You can use edge_endpoint_property: https://graph-tool.skewed.de/static/doc/graph_tool.html#graph_tool.edge_endp...
The example in that page is getting a numpy array of source vertices for all edges. It's very fast.
Another option is to use the adjacency() function that will return a sparse matrix. You can then get the edges with the nonzero() method:
a = ajacency(g) edges = a.nonzero()
Best, Tiago