Skip to content

Instantly share code, notes, and snippets.

@alexpreynolds
Last active August 29, 2015 13:57
Show Gist options
  • Save alexpreynolds/9795416 to your computer and use it in GitHub Desktop.
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
#!/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