Last active
August 29, 2015 14:25
-
-
Save erochest/ad0f06a025d3b07c9b8f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
def dist(xs, ys): | |
return math.sqrt(sum((x-y)**2 for (x, y) in zip(xs, ys))) |
This file contains hidden or 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
get_weight = operator.itemgetter(2) | |
links = [] | |
for (i, (w0, rows0)) in enumerate(by_word): | |
for (j, (w1, rows1)) in enumerate(by_word): | |
if w0 == w1: | |
continue | |
weights0 = (get_weight(w) for w in rows0) | |
weights1 = (get_weight(w) for w in rows1) | |
links.append({ | |
'source': i, | |
'target': j, | |
'weight': dist(weights0, weights1), | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment