Hello Claudio, Claudio Martella wrote:
Hello list,
I'm going on with my algorithms and i'm stuck on a thing: I cannot find the interface on graph_tool to access the adjacency matrix of the graph.
The rationale behind my request is that i have a graph and i have a matrix based algorithm to calculate new edges and new weights. So I'd like to:
(1) create a graph through the usual API (2) get its adjacency matrix (3) modify it with my matrix operations based algorithm (4) feed it back to the graph / create a new graph from the matrix
What is your suggestion to do this in graph_tool?
Step 2 can be done with the adjacency() function of the spectral module: http://projects.forked.de/graph-tool/doc/spectral.html#graph_tool.spectral.a... Step 4 needs to be done by hand, but it should be something as simple as: for i in xrange(N): for j in xrange(N): if a[i,j] != 0: g.add_edge(g.vertex(i), g.vertex(j)) Cheers, Tiago