I want to compare two different files in python. They contain lines with probabilities, and each line has an in id in the end of the file. I need to calculate ratio of each id. The problem is that each line might contain different number of probabilities and eventually, each text a different number of lines. I succeeded in doing a script that compares just two files with one line, but I do not know how to do it for each line in the text. Here is my script so far:
#!/usr/bin/python
import math
import operator
f = open('output.txt','w')
file1= open("test.ppx1","r")
file2= open("test.prob1","r")
words = list(file1.read().split())
words2 = list(file2.read().split())
id1=words[-1]
id2=words2[-1]
words.remove(id1)
words2.remove(id2)
words[:]=[x[:12] for x in words]
words2[:]=[x[:12] for x in words2]
words=map(float,words)
words2=map(float,words2)
words=[math.log(y,10) for y in words]
words2=[math.log(y,10) for y in words2]
words=sum(words)
words2=sum(words2)
ratio= words-words2
print >>f, id1,words, words2,ratio
Aucun commentaire:
Enregistrer un commentaire