#!/bin/python ################################################################################ # # MarkovCat - Joe Mariglio # #=============================================================================== # # reads in two transition matrices and concatenates them # usage: markovCat # ################################################################################ import cPickle, os.path, sys def concat(a, b): for key in b.keys(): if key in a.keys(): a[key].extend(b[key]) else: a[key] = b[key] return a def main(argv): if len(sys.argv) == 4: inpath_A = sys.argv[1] inpath_B = sys.argv[2] outpath = sys.argv[3] print "opening files..." infile_A = open(inpath_A, 'r') infile_B = open(inpath_B, 'r') outfile = open(outpath, "w") print "unpickling matrices..." print "A..." dic_A = cPickle.load(infile_A) print "B..." dic_B = cPickle.load(infile_B) print "concatenating..." dic_C = concat(dic_A, dic_B) print "writing new file..." print dic_C.keys() print dic_C.values() cPickle.dump(dic_C, outfile) print "finishing up..." infile_A.close infile_B.close outfile.close if __name__ == '__main__': import cPickle, os.path, sys main(sys.argv[1:])