多重のリスト内包表記で並列計算を行いたいと考えています。
具体的には簡単な例ではありますが、以下のような2重のリストの計算をmultiprocessingで並列化したいです。
python
1[[x + y 2 for y in range(2, 7, 2)] 3 for x in range(3, 5, 1)]
以下のプログラムのように、1次元リストとして出力することは可能ですが、できれば2次元リストとして取得したいと考えています。
python
1 2import numpy as np 3from multiprocessing import Pool 4 5def main(x, y): 6 return x+ y 7 8def wrapper(args): 9 return main(*args) 10 11def multi_process(sampleList): 12 # Number of processes: 12 (parallel processing with 12 cpu) 13 p = Pool(12) 14 output = p.map(wrapper, sampleList) 15 p.close() # Terminate the process 16 return output 17 18sampleList = [ 19 (x, y) 20 for x in np.arange(2, 7, 2) 21 for y in np.arange(3, 5, 1) 22 ] 23allinfo = multi_process(sampleList) 24 25allinfo 26 27# [5, 6, 7, 8, 9, 10] 28
どのようにしたらよろしいでしょうか。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。