Created
January 9, 2012 00:50
-
-
Save tpoisot/1580314 to your computer and use it in GitHub Desktop.
[Python] Number of co-occurences / draft
This file contains 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
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