Jul-07-2017, 09:34 PM
Hey guys, I'm trying to run a few files through a loop, but the run time is way to high. I am wondering if there is an issue with the way I coded it, that could cut down the time it takes to run the file.
Thanks!
This is a class that the files are read into and concatenated into a single file to be accessed by row.
Thanks!
This is a class that the files are read into and concatenated into a single file to be accessed by row.
class TextFiles: ''' This Class will read in all the text data files. These files will then be used to compare data from the read in binary files. ''' def __init__(self, txt1, txt2, txt3, txt4, txt5): text_data = self._textfile_data(txt1, txt2, txt3, txt4, txt5) self._text_data = text_data def _textfile_data(self, file1, file2, file3, file4, file5): ''' This method places the read in text files into a 2D numpy array. The zero column is then deleted removing the scan number. The arrays are then concatenated together, making a single numpy array of the data. ''' data1 = np.loadtxt(file1, delimiter = '\t', skiprows = 1) data1 = np.delete(data1, [0], axis = 1) data2 = np.loadtxt(file2, delimiter = '\t', skiprows = 1) data2 = np.delete(data2, [0], axis = 1) data3 = np.loadtxt(file3, delimiter = '\t', skiprows = 1) data3 = np.delete(data3, [0], axis = 1) data4 = np.loadtxt(file4, delimiter = '\t', skiprows = 1) data4 = np.delete(data4, [0], axis = 1) data5 = np.loadtxt(file5, delimiter = '\t', skiprows = 1) data5 = np.delete(data5, [0], axis = 1) text_data_array = np.concatenate((data1, data2, data3, data4, data5), axis = 1) return text_data_arrayThis is where the files are being used.
for x in range(len(dictionary._key_data(key_filename))-1): plt.plot(range(0,n), dictionary[next(current_key)], linewidth = 0.25) plt.plot(range(0,n), files._textfile_data(textfile1, textfile2, textfile3, textfile4, textfile5)[:,x], ':', linewidth = 0.25) ei = (sum(dictionary[dictionary._key_data(key_filename)[x]]) - (sum(files._textfile_data(textfile1, textfile2, textfile3, textfile4, textfile5)[:,x]))) MAE = abs(ei)/n