Skip to content

Instantly share code, notes, and snippets.

@tpoisot
Created January 9, 2012 00:50
Show Gist options
  • Save tpoisot/1580314 to your computer and use it in GitHub Desktop.
Save tpoisot/1580314 to your computer and use it in GitHub Desktop.
[Python] Number of co-occurences / draft
def COFM(comat,normal=True):
CoFreq = []
for sp1 in xrange(len(comat)-1):
for sp2 in xrange(sp1,len(comat)):
NCo = 0
for nsite in xrange(len(comat[0])):
if comat[sp1][nsite]*comat[sp2][nsite] > 0:
NCo += 1
if normal:
NCo /= len(comat[0])
CoFreq.append(NCo)
return CoFreq
CoMat = [[0,0,1,0],[0,2,1,0],[1,1,0,1],[1,0,0,0]]
print COFM(CoMat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment