summaryrefslogtreecommitdiff
path: root/networkx/linalg/graphmatrix.py
diff options
context:
space:
mode:
authorJarrod Millman <jarrod.millman@gmail.com>2021-05-27 14:17:28 -0700
committerGitHub <noreply@github.com>2021-05-27 14:17:28 -0700
commitfec20e0a6767eca1b40f19e1cf06387cdaea0f13 (patch)
tree5506eb3dbe72a0f3893eca04e8171361db34f194 /networkx/linalg/graphmatrix.py
parentfc032996017983aca9b1910b9a51947d74def0f9 (diff)
downloadnetworkx-fec20e0a6767eca1b40f19e1cf06387cdaea0f13.tar.gz
Add dtype argument to adjacency_matrix (#4850)
and deprecate adj_matrix
Diffstat (limited to 'networkx/linalg/graphmatrix.py')
-rw-r--r--networkx/linalg/graphmatrix.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/networkx/linalg/graphmatrix.py b/networkx/linalg/graphmatrix.py
index 73147857..ab9460e3 100644
--- a/networkx/linalg/graphmatrix.py
+++ b/networkx/linalg/graphmatrix.py
@@ -96,7 +96,7 @@ def incidence_matrix(G, nodelist=None, edgelist=None, oriented=False, weight=Non
return A.asformat("csc")
-def adjacency_matrix(G, nodelist=None, weight="weight"):
+def adjacency_matrix(G, nodelist=None, dtype=None, weight="weight"):
"""Returns adjacency matrix of G.
Parameters
@@ -108,6 +108,10 @@ def adjacency_matrix(G, nodelist=None, weight="weight"):
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.
@@ -150,7 +154,21 @@ def adjacency_matrix(G, nodelist=None, weight="weight"):
to_dict_of_dicts
adjacency_spectrum
"""
- return nx.to_scipy_sparse_matrix(G, nodelist=nodelist, weight=weight)
+ return nx.to_scipy_sparse_matrix(G, nodelist=nodelist, dtype=dtype, weight=weight)
+
+
+def _adj_matrix_warning(G, nodelist=None, dtype=None, weight="weight"):
+ import warnings
+
+ warnings.warn(
+ (
+ "adj_matrix is deprecated and will be removed in version 3.0.\n"
+ "Use `adjacency_matrix` instead\n"
+ ),
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return adjacency_matrix(G, nodelist, dtype, weight)
-adj_matrix = adjacency_matrix
+adj_matrix = _adj_matrix_warning