summaryrefslogtreecommitdiff
path: root/networkx/linalg
diff options
context:
space:
mode:
authorPaula PĂ©rez Bianchi <44149844+paulitapb@users.noreply.github.com>2022-11-14 11:02:47 -0300
committerGitHub <noreply@github.com>2022-11-14 15:02:47 +0100
commitc6a1dc8a2897f99462a77be836788ce6690dc691 (patch)
tree75fe2d248a0a8fb045198fdabd5b05bb49c7e2c0 /networkx/linalg
parent838b06c2233b8b22df6c1f43e3a91a963749a89b (diff)
downloadnetworkx-c6a1dc8a2897f99462a77be836788ce6690dc691.tar.gz
add laplacian_spectrum example (#6169)
* add laplacian_spectrum example * add missing reference to_numpy_array * Update networkx/linalg/spectrum.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/linalg/spectrum.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Update networkx/linalg/spectrum.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * Rm unnecessary numpy import. Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
Diffstat (limited to 'networkx/linalg')
-rw-r--r--networkx/linalg/spectrum.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/networkx/linalg/spectrum.py b/networkx/linalg/spectrum.py
index caa95fc5..66aedbbd 100644
--- a/networkx/linalg/spectrum.py
+++ b/networkx/linalg/spectrum.py
@@ -32,11 +32,23 @@ def laplacian_spectrum(G, weight="weight"):
Notes
-----
For MultiGraph/MultiDiGraph, the edges weights are summed.
- See to_numpy_array for other options.
+ See :func:`~networkx.convert_matrix.to_numpy_array` for other options.
See Also
--------
laplacian_matrix
+
+ Examples
+ --------
+ The multiplicity of 0 as an eigenvalue of the laplacian matrix is equal
+ to the number of connected components of G.
+
+ >>> G = nx.Graph() # Create a graph with 5 nodes and 3 connected components
+ >>> G.add_nodes_from(range(5))
+ >>> G.add_edges_from([(0, 2), (3, 4)])
+ >>> nx.laplacian_spectrum(G)
+ array([0., 0., 0., 2., 2.])
+
"""
import scipy as sp
import scipy.linalg # call as sp.linalg