I am trying to speed up a piece of code by using concurrent.futures, however, the program does not fill the new matrix as intended. Code below:
data_new = np.random.random(6000000).reshape(100,200,300)
data_processed = np.zeros((100,200,300))
subs = [sub for sub in range(0,100)]
def processing(sub):
detrended = signal.detrend(data_new[sub])
std = StandardScaler()
fit = std.fit(detrended)
scaled_data = std.transform(detrended)
data_processed[sub] = scaled_data
print(f'Subject {sub} was processed...')
t1 = time.perf_counter()
if __name__ == '__main__':
with concurrent.futures.ProcessPoolExecutor() as executor:
executor.map(processing, subs)
t2 = time.perf_counter()
print(f'Finished in {t2-t1} seconds.')
Can anyone point out the mistake in my code. the new matrix# data_processed still contains only zeros however when I use for loop the code works. Thanks in advance.