Week 22: 1/29 – 2/2

This week, I focused on being able to pull the data that I needed for the matrix. Using python, I loaded the test.probs file then used regex to get the specific data that I want. I ended up with the following code:

import re

f = open(r"test.probs", "r")

data = []
while(True):

    line = f.readline()

    # When readline returns an empty string, the file is fully read.
    if line == "":
        break

    # When a newline is returned, the line is empty.
    if line == "\n":
        continue

    # Print other lines.
    stripped = line.strip()
    #print(stripped)

    m = re.match(r'.*\:([\d\.]+).*\:([\d\.]+).*', stripped)
    if m is not None:
            if float(m.group(1)) > float(m.group(2)):
                data.append((m.group(1), m.group(2), "left"))
            else:
                data.append((m.group(1), m.group(2), "right"))

 

“data” will look like so:

[('0.4712889790534973', '0.5287110805511475', 'right'), ('0.9078547954559326', '0.09214520454406738', 'left'), ('0.6792420148849487', '0.32075798511505127', 'left'), ('0.6792420148849487', '0.32075798511505127', 'left'), ('0.04402024671435356', '0.9559798240661621', 'right'), ('0.5282033085823059', '0.4717966616153717', 'left'), ('0.4712889790534973', '0.5287110805511475', 'right'), ('0.05213860794901848', '0.94786137342453', 'right'),...]

Where ‘left’ or ‘right’ is whichever number is bigger.