简体   繁体   English

multiprocessing.Array(python):预期为float而不是numpy.ndarray实例

[英]multiprocessing.Array (python): float expected instead of numpy.ndarray instance

I have followed online manual on multiprocessing already. 我已经遵循了有关多处理的在线手册。 I think I have given it an array to mp.Array. 我想我已经给它一个数组mp.Array。 Why does it expect a float instead of an array? 为什么会期望使用float而不是array?

My script - 我的剧本-

import multiprocessing as mp
import numpy as np

pdb_num = 1000

fitting_theta = mp.Array('d', np.zeros((pdb_num,pdb_num)))
fitting_deviation = mp.Array('d', np.zeros((pdb_num,pdb_num)))

And it gives an error - 它给出了一个错误-

float expected instead of numpy.ndarray instance

Thanks. 谢谢。

Edit : 编辑:

Complete traceback - 完整的追溯-

  File "/lustre/beagle2/danielhskerr/python/min_sq_fitnewres.py", line 70, in <module>
fitting_theta = mp.Array('d', np.zeros((pdb_num,pdb_num)))
  File "/soft/python/2.7/2.7.1/lib/python2.7/multiprocessing/__init__.py", line 256, in Array
return Array(typecode_or_type, size_or_initializer, **kwds)
  File "/soft/python/2.7/2.7.1/lib/python2.7/multiprocessing/sharedctypes.py", line 87, in Array
  obj = RawArray(typecode_or_type, size_or_initializer)
  File "/soft/python/2.7/2.7.1/lib/python2.7/multiprocessing/sharedctypes.py", line 61, in RawArray
result.__init__(*size_or_initializer)
TypeError:  float expected instead of numpy.ndarray instance

Please read the documentation to multiprocessing carefully: https://docs.python.org/2/library/multiprocessing.html#multiprocessing.Array 请仔细阅读文档以进行多处理: https : //docs.python.org/2/library/multiprocessing.html#multiprocessing.Array

The types available for marshalling between processes are quite limited, and thus you can't use an arbitrary object/type (such as an numpy-array) for them. 进程之间可用于编组的类型非常有限,因此您不能为它们使用任意对象/类型(例如numpy-array)。

This might be an answer to your problem 这可能是您的问题的答案

Use numpy array in shared memory for multiprocessing 在共享内存中使用numpy数组进行多处理

however the requirement to lock access might influence the performance unduly. 但是,锁定访问的要求可能会不适当地影响性能。 Use a normal array with floats instead for spawning your processes, and then build numpy-arrays from them. 使用带有浮点数的普通数组来生成进程,然后从它们中构建numpy-arrays。 But if one of these solutions is a fit to your problem depends on that very problem. 但是,如果其中一种解决方案适合您的问题,则取决于该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM