NetworkX

Previous topic

networkx.linalg.attrmatrix.attr_sparse_matrix

Next topic

networkx.linalg.spectrum.laplacian

networkx.linalg.spectrum.adj_matrix

networkx.linalg.spectrum.adj_matrix(G, nodelist=None)

Return adjacency matrix of G.

Parameters :

G : graph

A NetworkX graph

nodelist : list, optional

The rows and columns are ordered according to the nodes in nodelist. If nodelist is None, then the ordering is produced by G.nodes().

Returns :

A : numpy matrix

Adjacency matrix representation of G.

See also

to_numpy_matrix, to_dict_of_dicts

Notes

If you want a pure Python adjacency matrix representation try networkx.convert.to_dict_of_dicts which will return a dictionary-of-dictionaries format that can be addressed as a sparse matrix.