diff --git a/utils.py b/utils.py index 5a06dbd..2e00ca1 100755 --- a/utils.py +++ b/utils.py @@ -2,7 +2,7 @@ import math import random import os -import cPickle as pickle +import _pickle as pickle import xml.etree.ElementTree as ET from utils import * @@ -208,9 +208,13 @@ def to_one_hot(s, ascii_steps, alphabet): if len(seq) >= ascii_steps: seq = seq[:ascii_steps] else: - seq = seq + [0]*(ascii_steps - len(seq)) - one_hot = np.zeros((ascii_steps,len(alphabet)+1)) - one_hot[np.arange(ascii_steps),seq] = 1 + #print(ascii_steps - len(seq)) + seq = seq + np.multiply([0],(ascii_steps - len(seq))) + one_hot = np.zeros((int(ascii_steps),len(alphabet)+1)) + seq=np.array(seq,dtype=int) + seq=np.pad(seq,(0,len(np.arange(ascii_steps))-len(seq))) + + one_hot[np.arange(ascii_steps,dtype=int),seq] = 1 return one_hot # abstraction for logging @@ -221,6 +225,6 @@ def __init__(self, args): def write(self, s, print_it=True): if print_it: - print s + print(s) with open(self.logf, 'a') as f: f.write(s + "\n")