Skip to content

Commit

Permalink
Minor touchups to adjacency_matrix docstring.
Browse files Browse the repository at this point in the history
  • Loading branch information
rossbar committed Sep 9, 2024
1 parent fb1b2e4 commit 3e87b53
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions networkx/linalg/graphmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,21 @@ def incidence_matrix(

@nx._dispatchable(edge_attrs="weight")
def adjacency_matrix(G, nodelist=None, dtype=None, weight="weight"):
"""Returns adjacency matrix of G.
"""Returns 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().
The rows and columns are ordered according to the nodes in `nodelist`.
If ``nodelist=None`` (the default), 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.
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.
Expand All @@ -133,29 +134,29 @@ def adjacency_matrix(G, nodelist=None, dtype=None, weight="weight"):
Notes
-----
For directed graphs, entry i,j corresponds to an edge from i to j.
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
:func:`~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.
For multigraphs with parallel edges the weights are summed.
See :func:`networkx.convert_matrix.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 array 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]]
resulting SciPy sparse array can be modified as follows::
>>> G = nx.Graph([(1, 1)])
>>> A = nx.adjacency_matrix(G)
>>> A.toarray()
array([[1]])
>>> A.setdiag(A.diagonal() * 2)
>>> A.toarray()
array([[2]])
See Also
--------
Expand Down

0 comments on commit 3e87b53

Please sign in to comment.