Build a graph from the adjacency matrix
Hi there ! I'm wondering if possible to build a graph starting from the adjacency matrix. Having such a matrix matrix = [[1.0, 0.0], [1.0, 1.0]] I'd like to build its graph (0) --- (0) (1) --- (0) (1) --- (1) Thank you in advance. Marco. -- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
On 05/08/2014 06:15 PM, marklasta wrote:
Hi there !
I'm wondering if possible to build a graph starting from the adjacency matrix.
Having such a matrix
matrix = [[1.0, 0.0], [1.0, 1.0]]
I'd like to build its graph
(0) --- (0)
(1) --- (0)
(1) --- (1)
Yes, you should do: adj = numpy.array(matrix) g = Graph() g.add_edge_list(transpose(adj.nonzero())) Best, Tiago -- Tiago de Paula Peixoto <tiago@skewed.de>
participants (2)
-
marklasta -
Tiago de Paula Peixoto