如何解决如何在并行映射中传递“常量”参数?
过去几天,我一直在处理一些问题,即当我映射某个函数时,据说在主“程序”中定义的变量没有定义。
无论如何,我认为解决方案是将这些变量作为参数传递,但即使那样,我还是尝试使用MWE进行操作,但我失败了!
这可能是显而易见的,因此,对于此事,提前致歉。在这里:
功能:
def arar(a1,*a3):
a2=[]
a2.append(a1+a3[0])
return(a2)
testloop=np.array([1,2,3,4])
的结果:
testloop = np.array([1,4])
args = 1
a4=[]
for i in testloop:
a4.append(arar(i,args))
print a4
>>>[[2],[3],[4],[5]]
和“平行”尝试:
testloop = np.array([1,4])
import multiprocessing as mp
pool = mp.Pool(4)
aaaa = pool.map(arar,testloop)
print(aaaa)
>>> [1,4]
结果正确,但是我无法将args
传递给map()
函数,所以我得到[2,4,5]
。
解决方法
以下是我在评论中建议的使用functools.partial
的方法:
ERROR in node_modules/ngx-loading/lib/ngx-loading.module.d.ts:4:55 - error TS2314: Generic type 'ModuleWithProviders<T>' requires 1 type argument(s).
4 static forRoot(loadingConfig: INgxLoadingConfig): ModuleWithProviders;
~~~~~~~~~~~~~~~~~~~
src/app/export/export.component.ts:83:24 - error TS2351: This expression is not constructable.
Type 'typeof import("jspdf")' has no construct signatures.
83 const pdfDoc = new jsPDF('l');
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。