Last active
August 29, 2015 13:57
-
-
Save alexpreynolds/9795416 to your computer and use it in GitHub Desktop.
Output the minimum value in an adjacency matrix, along with a list of row and column IDs for that minimum value
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
#!/usr/bin/env python | |
import sys | |
fn = sys.stdin | |
ids = list() | |
vd = dict() | |
rowIdx = -1 | |
for line in fn: | |
vals = line.strip("\n\t").split("\t") | |
if rowIdx == -1: | |
ids = vals | |
else: | |
yid = vals[0] | |
vals.pop(0) | |
for colIdx in xrange(len(vals)): | |
xid = ids[colIdx] | |
val = float(vals[colIdx]) | |
if val > 0.0 and val not in vd.keys(): | |
vd[val] = list() | |
if val > 0.0: | |
vd[val].append([xid, yid]) | |
rowIdx += 1 | |
print min(vd), vd[min(vd)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment