networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
adjacency_matrix(G, nodelist=None, dtype=None, weight='weight')

Notes

For directed graphs, entry i,j corresponds to an edge from i to j.

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.

For MultiGraph/MultiDiGraph with parallel edges the weights are summed. See to_numpy_array for other options.

The convention used for self-loop edges in graphs is to assign the diagonal matrix entry value to the edge weight attribute (or the number 1 if the edge has no weight attribute). If the alternate convention of doubling the edge weight is desired the resulting Scipy sparse matrix can be modified as follows:

>>> G = nx.Graph([(1, 1)])
>>> A = nx.adjacency_matrix(G)
>>> print(A.todense())
[[1]]
>>> A.setdiag(A.diagonal() * 2)
>>> print(A.todense())
[[2]]

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().

dtype : NumPy data-type, optional

The desired data-type for the array. If None, then the NumPy default is used.

weight : string or None, optional (default='weight')

The edge data key used to provide each value in the matrix. If None, then each edge has weight 1.

Returns

A : SciPy sparse matrix

Adjacency matrix representation of G.

Returns adjacency matrix of G.

See Also

adjacency_spectrum
to_dict_of_dicts
to_numpy_array
to_scipy_sparse_array

Examples

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.utils.rcm.reverse_cuthill_mckee_ordering networkx.linalg.spectrum.adjacency_spectrum networkx.utils.rcm.cuthill_mckee_ordering networkx.linalg.modularitymatrix.modularity_matrix networkx.algorithms.bipartite.matrix.biadjacency_matrix networkx.linalg.modularitymatrix.directed_modularity_matrix networkx.linalg.bethehessianmatrix.bethe_hessian_matrix

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/linalg/graphmatrix.py#107
type: <class 'function'>
Commit: