前提・実現したいこと
python標準のmap関数であれば以下のコードで普通に計算することができます。
python3
1def calc(x, y, z): 2 return x*y*z 3 4t1 = [1,2,3,4,5] 5t2 = [3,4,5,6,7] 6t3 = [3,4,5,6,7] 7 8result = map(calc, t1, t2, t3) 9print(list(result)) 10 11#[9, 32, 75, 144, 245]
multiprocessingのPool.mapで上記のコードと同じく処理させたいのですが、できません。
どうすればよいでしょうか。
発生している問題・エラーメッセージ
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-102-53f60d42d54f> in <module> 7 8 with Pool() as pool: ----> 9 result = pool.map(calc, t1, t2, t3) 10 print(list(result)) TypeError: map() takes from 3 to 4 positional arguments but 5 were given
該当のソースコード
python3
1from multiprocessing import Pool 2 3def calc(x, y, z): 4 return x*y*z 5 6t1 = [1,2,3,4,5] 7t2 = [3,4,5,6,7] 8t3 = [3,4,5,6,7] 9 10with Pool() as pool: 11 result = pool.map(calc, t1, t2, t3) 12print(list(result))
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/02 11:58 編集