summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoss Barnowski <rossbar@berkeley.edu>2022-02-22 13:54:49 -0800
committerGitHub <noreply@github.com>2022-02-22 13:54:49 -0800
commit12d5f9bae34cd8ecc6e63aef0f7bea9542aeddc0 (patch)
tree2a530c6bbefe1742a2bfe7cf5598a640a82850d4
parent42985ba7d9f768c32c651e3e73d4d98b46776f54 (diff)
downloadnetworkx-12d5f9bae34cd8ecc6e63aef0f7bea9542aeddc0.tar.gz
Use np.random.default_rng in example + other updates. (#5356)
-rw-r--r--networkx/convert_matrix.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/networkx/convert_matrix.py b/networkx/convert_matrix.py
index c38762d3..2ccaf01a 100644
--- a/networkx/convert_matrix.py
+++ b/networkx/convert_matrix.py
@@ -1,21 +1,24 @@
"""Functions to convert NetworkX graphs to and from common data containers
-like numpy arrays, scipy sparse matrices, and pandas DataFrames.
+like numpy arrays, scipy sparse arrays, and pandas DataFrames.
The preferred way of converting data to a NetworkX graph is through the
-graph constructor. The constructor calls the to_networkx_graph() function
-which attempts to guess the input type and convert it automatically.
+graph constructor. The constructor calls the `~networkx.convert.to_networkx_graph`
+function which attempts to guess the input type and convert it automatically.
Examples
--------
Create a 10 node random graph from a numpy array
>>> import numpy as np
->>> a = np.random.randint(0, 2, size=(10, 10))
->>> D = nx.DiGraph(a)
+>>> rng = np.random.default_rng()
+>>> a = rng.integers(low=0, high=2, size=(10, 10))
+>>> DG = nx.from_numpy_array(a, create_using=nx.DiGraph)
-or equivalently
+or equivalently:
->>> D = nx.to_networkx_graph(a, create_using=nx.DiGraph)
+>>> DG = nx.DiGraph(a)
+
+which calls `from_numpy_array` internally based on the type of ``a``.
See Also
--------