Skip to content

Commit

Permalink
make doc_string examples order-independent by removing np.set_printop…
Browse files Browse the repository at this point in the history
…tions (#7361)

remove np.set_printoptions from normalized_laplacian_matrix doc_string example
  • Loading branch information
dschult committed Mar 20, 2024
1 parent bc94afe commit 1b34ffe
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions networkx/linalg/laplacianmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ def normalized_laplacian_matrix(G, nodelist=None, weight="weight"):
--------
>>> import numpy as np
>>> np.set_printoptions(precision=4) # To print with lower precision
>>> edges = [
... (1, 2),
... (2, 1),
Expand All @@ -189,27 +188,27 @@ def normalized_laplacian_matrix(G, nodelist=None, weight="weight"):
... ]
>>> DiG = nx.DiGraph(edges)
>>> print(nx.normalized_laplacian_matrix(DiG).toarray())
[[ 1. -0.7071 0. 0. ]
[-0.7071 1. -0.7071 0. ]
[ 0. 0. 1. -1. ]
[ 0. 0. -1. 1. ]]
[[ 1. -0.70710678 0. 0. ]
[-0.70710678 1. -0.70710678 0. ]
[ 0. 0. 1. -1. ]
[ 0. 0. -1. 1. ]]
Notice that node 4 is represented by the third column and row. This is because
by default the row/column order is the order of `G.nodes` (i.e. the node added
order -- in the edgelist, 4 first appears in (2, 4), before node 3 in edge (4, 3).)
To control the node order of the matrix, use the `nodelist` argument.
>>> print(nx.normalized_laplacian_matrix(DiG, nodelist=[1, 2, 3, 4]).toarray())
[[ 1. -0.7071 0. 0. ]
[-0.7071 1. 0. -0.7071]
[ 0. 0. 1. -1. ]
[ 0. 0. -1. 1. ]]
[[ 1. -0.70710678 0. 0. ]
[-0.70710678 1. 0. -0.70710678]
[ 0. 0. 1. -1. ]
[ 0. 0. -1. 1. ]]
>>> G = nx.Graph(edges)
>>> print(nx.normalized_laplacian_matrix(G).toarray())
[[ 1. -0.7071 0. 0. ]
[-0.7071 1. -0.5 0. ]
[ 0. -0.5 1. -0.7071]
[ 0. 0. -0.7071 1. ]]
[[ 1. -0.70710678 0. 0. ]
[-0.70710678 1. -0.5 0. ]
[ 0. -0.5 1. -0.70710678]
[ 0. 0. -0.70710678 1. ]]
See Also
--------
Expand Down

0 comments on commit 1b34ffe

Please sign in to comment.