2
votes

I am having a numpy 2D array, with the values representing the weights of edges between nodes. The matrix is symmetric, and I take the diagonal to be zero. I don't find an example of how to convert this matrix into igraph Graph object. I've tried the following approach, but it doesn't work:

import numpy as np
import igraph

def symmetrize(a):
    return a + a.T - 2*np.diag(a.diagonal())

A = symmetrize(np.random.random((100,100)))

G = igraph.Graph.Adjacency(A.tolist())
1

1 Answers

4
votes

Use Graph.Weighted_Adjacency() if you want to preserve the original values in the matrix as weights. The weights will be attached as the weight edge attribute to the graph that igraph creates.