Last active
August 29, 2015 14:22
-
-
Save changwu-tw/c16708bcf2d4eba173e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import networkx as nx | |
import matplotlib.pyplot as plt | |
G = nx.Graph() | |
G.add_edges_from([('A', 'B'), ('B', 'C'), ('C', 'D'), ('D', 'E'), ('E', 'A'), ('A', 'D')]) | |
L = nx.laplacian_matrix(G) | |
e = nx.laplacian_spectrum(G) | |
print "Largest eigenvalue:", max(e) | |
print "Smallest eigenvalue:", min(e) | |
plt.hist(e, bins=100) | |
plt.xlim(0, math.ceil(max(e))) | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import networkx as nx | |
import matplotlib.pyplot as plt | |
A = np.matrix([[0,1,0,0,0,0],[1,0,1,0,0,0],[0,1,0,1,1,1],[0,0,1,0,1,0],[0,0,1,1,0,1],[0,0,1,0,1,0]]) | |
print A | |
G = nx.from_numpy_matrix(A) | |
nx.draw(G, with_labels=True) | |
plt.show() | |
e = np.linalg.eigvals(A) | |
print e | |
print "Largest eigenvalue:", max(e) | |
print "Smallest eigenvalue:", min(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment