from multiprocessing import Pool
a=[1,2,3,4,5,6]
def func1(a):
return a**2
def func2(a):
x= np.zeros(1)
for i in a:
x += i
return x
if __name__ == "__main__":
pool = Pool( os.cpu_count())
results = pool.map(func1, a)
print(results)
and then I need
func2(results) This is just a simple example of my problem . Please don't tell me to transfer a to numpy array first because my func2 is way more complicated than this example. Does anyone know how to do it please? I tried something like this, but it didn't work.
from itertools import repeat
from multiprocessing import Pool
import os
import numpy as np
a=[1,2,3,4,5,6]
def func1(a):
return a**2
def func2(a):
x= np.zeros(1)
for i in a:
x += i
return x
def func22():
if __name__ == "__main__":
pool = Pool( os.cpu_count())
results = pool.map(func1, a)
x= func2(results)
return x
print(func22())
Thank you very much.