0
votes

Good afternoon, May I please get advice on how to proceed with a section of Python code that I have? I have an array that is 1000 columns wide, and I wish to apply .h5 files to each section. For example:

data_len=list(range(100,1100,300)) 
score_set = np.zeros((len(data_len),2))
ind = 0
for end_pt in data_len:

# ITERATE OVER .H5 FILES
directory = r'/media/Thesis_Maps/test_runs_2/h5_files'

for file in os.listdir(directory): #setup for loop to read each .h5 file
    filename=os.fsdecode(file)
    if filename.endswith('.h5'):
        fpath=os.path.join(directory,filename)
        model = load_model(fpath)
        #model.summary()
        X_run = X.iloc[:,0:end_pt]
        y_run = y.iloc[:,0:end_pt] 

I was hoping to break the 1000 rows into 4 groups of 100, 300, 300 and 300. However, I think this is not doing that, it is instead creating groups of 100, 400, 700 and 1000, which is incorrect. The question is, how do I break up a 1000 column-wide row into 100, 300, 300 and 300 data points, applying a unique .h5 file to each? Any advice would be awesome, thank you.

1

1 Answers

0
votes

You can fix your limits:

import numpy as np

data_len=list(range(100,1100,300)) 
score_set = np.zeros((len(data_len),2))
ind = 0
so_far = 0
for end_pt in data_len:
    end_pt -= so_far   # fix your list above
    so_far += end_pt   # remember how much so far
    print(end_pt)

Output:

100
300
300
300