By writing
import igraph
g = igraph.Graph()
g.add_vertices(6)
g.add_edges([(0,1),(0,3),(0,4),(0,5),(1,2),(2,4),(2,5),(3,0),(3,2),(3,5),(4,5),(3,3)])
A=g.get_adjacency()
I get the adjacency matrix of graph g, as a Matrix object. I want to calculate its eigenvalues by using, for example, numpy.linalg.eigvals()
. This method takes a numpy array object as argument.
How do I convert a Matrix object into a numpy array object?
I tried by using
X=numpy.matrix(A)
but it produced some mixture of the two and eigenvalues could not be calculated.
According to the documentation of iGraph's matrix class, you could retrieve the data as a list of lists and then convert easily to a numpy ndarray:
A = g.get_adjacency()
A = np.array(A.data)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With