python - Don't understand: ValueError: operands could not be broadcast together with shapes -


i have code create processes , opearate 2 own arrays each "threads" using lock scheme:

if __name__ == "__main__":     geom_file = sys.argv[1]     filename = sys.argv[2]     event = none     resolution = 5814.0      dist = 0.2     n_3d = 501  # num of points      output_array = []      pixm = cg.pixel_maps_from_geometry_file(geom_file) #getting pairs of coordinates in 3d     x_array = pixm.x.flatten()     y_array = pixm.y.flatten()     z_array = np.ones_like(x_array) * dist      open(filename,'r') stream:         #reading stream file ang getting necessary info         lines = stream.readlines()         output_array = get_opt_patterns(lines)      i_xyz_buf = rawarray(ct.c_double, n_3d * n_3d * n_3d)     count_dot_buf = rawarray(ct.c_double, n_3d * n_3d * n_3d)       mask_buf = rawarray(ct.c_int, len(x_array))      result_lock = lock()     mask_lock = lock()        pool = pool(os.cpu_count(),                 initializer=init_worker,                 initargs=(result_lock, mask_lock,                           i_xyz_buf, count_dot_buf, mask_buf,                           x_array, y_array, z_array))       pool.map(processing, output_array)      i_xyz = np.frombuffer(i_xyz_buf, dtype=np.double)     count_dot = np.frombuffer(count_dot_buf, dtype=np.double) 

after running shows me following errors:

traceback (most recent call last):

file "/opt/anaconda/3/lib/python3.5/multiprocessing/process.py", line 254, in _bootstrap self.run() file "/opt/anaconda/3/lib/python3.5/multiprocessing/process.py", line 93, in run self._target(*self._args, **self._kwargs) file "/opt/anaconda/3/lib/python3.5/multiprocessing/pool.py", line 103, in worker initializer(*initargs) file "processing.py", line 340, in init_worker mask_arr = np.frombuffer(mask_buf, dtype=np.int)  valueerror: buffer size must multiple of element size 

creating worker:

def init_worker(res_lck, mask_lck,             i_xyz_buf, count_dot_buf, mask_buf,             x_arr, y_arr, z_arr):      global result_lock     global mask_lock      global i_xyz_arr     global count_dot_arr     global mask_arr      global x_array     global y_array     global z_array      i_xyz_arr = np.frombuffer(i_xyz_buf, dtype=np.double)     count_dot_arr = np.frombuffer(count_dot_buf, dtype=np.double)     mask_arr = np.frombuffer(mask_buf, dtype=np.int)      result_lock = res_lck     mask_lock = mask_lck      x_array = x_arr     y_array = y_arr     z_array = z_arr 

and function responsible obtaining :

def new_sphere_evald(x_array, y_array, z_array, mask, int, k):     global resolution     global n_3d      global mask_lock      len_array = len(x_array)      qx = x_array / 2 + n_3d / 5     qy = y_array * 3 - n_3d / 100     qz = z_array / resolution      mask_lock:         indexes = np.where((qx < n_3d) &                            (qy < n_3d) &                            (qz < n_3d) &                            (mask != mask_bad))[0]      coords = np.array((qx, qy, qz), dtype=np.int32)[:, indexes]     coords_intens = int[indexes]     intensity = np.histogramdd(coords.t,                                bins=[np.arange(0, n_3d + 1, 1),                                      np.arange(0, n_3d + 1, 1),                                      np.arange(0, n_3d + 1, 1)],                                normed=false,                                weights=coords_intens)[0]      click_count = np.histogramdd(coords.t,                                  bins=[np.arange(0, n_3d + 1, 1),                                        np.arange(0, n_3d + 1, 1),                                        np.arange(0, n_3d + 1, 1)])[0]      return intensity, click_count   def get_opt_patterns(lines):     ....     # metadata = [name_of_file,energy,len_of_camera,[a,b,c,alpha,betta,gamma],[[a1*,a2*,a3*],[b1*,b2*,b3*],[c1*,c2*,c3*]]]     return metadata   def processing(i):     global result_lock     global mask_lock      global i_xyz_arr     global count_dot_arr     global mask_arr      global x_array     global y_array     global z_array      len_array = len(x_array)      name_of_file = i[0]     # print(name_of_file)     f = h5.file(name_of_file, 'r')  # h5.file(sys.argv[1],'r')     int = f['data/data']     int = np.reshape(int, len_array)      index = int >= 0      mask_lock:         mask_arr[index] = mask_good      k = i[1] * (1e10) / 12.4      intensity, click_count = new_sphere_evald(x_array, y_array, z_array, mask_arr, int, k)  # higher      result_lock:         i_xyz_arr += intensity         count_dot_arr += click_count.astype(count_dot_arr.dtype) 

what should note , repair? first time face neccesary using of multiprocess.


try: dtype="int32"

it solve 1 problem. appear another:

line 119, in worker  result = (true, func(*args, **kwds))   file "/opt/anaconda/3/lib/python3.5/multiprocessing/pool.py", line 44, in mapstar   return list(map(*args))  file "processing.py", line 319, in processing  i_xyz_arr += intensity   valueerror: operands not broadcast shapes      (125751501,) (501,501,501) (125751501,) 


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -