Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
42 lines (36 sloc) 1.08 KB
import json
import networkx as net
import matplotlib.pyplot as plot
def trim_degrees(g, degree=1):
Trim the graph by removing nodes with degree less then value of the degree parameter
Returns a copy of the graph, so it's non-destructive.
for n in g2.nodes():
if d[n]<=degree: g2.remove_node(n)
return g2
def sorted_degree(g):
ds = sorted(d.iteritems(), key=lambda (k,v): (-v,k))
return ds
def add_or_inc_edge(g,f,t):
Adds an edge to the graph IF the edge does not exist already.
If it does exist, increment the edge weight.
Used for quick-and-dirty calculation of projected graphs from 2-mode networks.
if g.has_edge(f,t):
def trim_edges(g, weight=1):
Remove edges with weights less then a threshold parameter ("weight")
for f, to, edata in g.edges(data=True):
if edata['weight'] > weight:
return g2
Jump to Line
Something went wrong with that request. Please try again.