다중 처리를 사용하여 다음 스크립트에서 data1 배열을 채 웁니다. 지금은 스크립트가 제대로 실행되지만 배열이 채워지지 않습니다. this을 구현하려고했지만 두 개의 iterables를 사용하기 때문에 작동하지 못했습니다. 도움말 감사; 감사! 그건 그렇고, 나는 최신 MacOS에서 jupyter 노트북을 사용합니다.다중 처리로 3D 배열 채우기
import numpy as np
import multiprocessing as mp
from itertools import product
#Generate random data:
data = np.random.randn(12,20,20)
#Create empty array to store the result
data1 = np.zeros((data.shape), dtype=np.float)
#Define the function
def fn(parameters):
i = parameters[0]
j = parameters[1]
data1[:,i,j] = data[:,i,j]
#Generate processes equal to the number of cores
pool = mp.Pool(processes=4)
# Generate values for each parameter: i.e. i and j
i = range(data.shape[1])
j = range(data.shape[2])
#generate a list of all combinations of the parameters
paramlist = list(product(i,j))
#call the function and multiprocessing
np.array(pool.map(fn,paramlist))
pool.close()
코드에서 "제품"기능은 무엇입니까? 마주 치게되는 정확한 문제는 무엇입니까? – mommermi
@mommermi '제품'은 'itertools'에서 가져온 것입니다. 문제는 data1 배열이 함수를 호출 한 후에 채워지지 않는다는 것입니다. 이를 분명히하기 위해 원래 게시물을 수정했습니다. 감사! – hrishi