forked from edmundyan/yelp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgutils.py
More file actions
31 lines (26 loc) · 739 Bytes
/
Copy pathgutils.py
File metadata and controls
31 lines (26 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np
import matplotlib.pyplot as plt
from collections import defaultdict
def avgDegree(G):
print "Nodes: ",
print G.number_of_nodes()
print "Edges: ",
print G.number_of_edges()
# avg degree
degrees = defaultdict(int)
total = 0
for node in G.nodes():
neighbors = G.neighbors(node)
degrees[len(neighbors)] += 1
total += len(neighbors)
max_degree = max(degrees.keys())
degrees_arr = (max_degree+1) * [0]
for index, count in degrees.iteritems():
degrees_arr[index] = count
plt.plot(range(max_degree+1), degrees_arr, '.')
plt.xscale('log', basex=2)
plt.xlabel('degree')
plt.yscale('log', basex=2)
plt.ylabel('# of people')
plt.savefig('degree_distribution.png')
plt.close()