Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to accelerate the application of the following for loop and function?

I have the following for loop:

for j in range(len(list_list_int)):
    arr_1_, arr_2_, arr_3_ = foo(bar, list_of_ints[j])
    arr_1[j,:] = arr_1_.data.numpy()
    arr_2[j,:] = arr_2_.data.numpy()
    arr_3[j,:] = arr_3_.data.numpy()

I would like to apply foo with multiprocessing, mainly because it is taking a lot of time to finish. I tried to do it in batches with funcy's chunks method:

for j in chunks(1000, list_list_int):
    arr_1_, arr_2_, arr_3_ = foo(bar, list_of_ints[j])
    arr_1[j,:] = arr_1_.data.numpy()
    arr_2[j,:] = arr_2_.data.numpy()
    arr_3[j,:] = arr_3_.data.numpy()

However, I am getting list object cannot be interpreted as an integer. What is the correct way of applying foo using multiprocessing?

like image 786
anon Avatar asked May 15 '19 05:05

anon


1 Answers

list_list_int = [1,2,3,4,5,6]
for j in chunks(2, list_list_int):
  for i in j:
    avg_, max_, last_ = foo(bar, i)
like image 126
Yang Yu Avatar answered Sep 23 '22 12:09

Yang Yu