0
votes

So I'm trying to construct a graph using igraph and an adjacency matrix that I have. It's a symmetrical matrix with ones where there should be an edge between two nodes and zeros where there is no connection. I'm using the code below to generate it:

g = igraph.Graph.Adjacency(adjacency)
igraph.plot(g, layout = 'kk')

My adjacency matrix is type

numpy.matrixlib.defmatrix.matrix

But I tried to convert it to a list and an array and still get the same error:

TypeError: Error while converting adjacency matrix

Any ideas? Thanks

1

1 Answers

2
votes

The Adjacency method of igraph.Graph expects a matrix of the type igraph.datatypes.Matrix, not a numpy matrix.

igraph will convert a list of lists to a matrix. Try using

g = igraph.Graph.Adjacency(adjacency.astype(bool).tolist())

where adjacency is your numpy matrix of zeros and ones.