저는 하이퍼 스펙트 럴 이미징과 비슷한 이미지의 각 픽셀에 대한 데이터를 포함하는이 데이터 큐브를 가지고 있습니다. 효율적인 방법으로 이미지의 각 픽셀에 선을 맞추려고합니다. 지금은 이렇게하고 있습니다 :중첩 루프 연산 최적화
내 데이터 큐브는 6X1024x1024입니다. 내 데이터의 독립 변수를 포함하는 다른 변수가 있습니다.
map = np.zeros((1024,1024))
for i in np.mgrid[1:1024]:
for j in np.mgrid[1:1024]:
x = independent_variable # This is my independent variable
y = spec_cube[:,i,j] # The Y data to be fitted is the power at each scale, for a pixel
index = polyfit(x,y,1) # Outputs the slope and the offset
map[i,j] = index[0] # The pixel value is the index
나는 루프에 대한 중첩 된 거의 일반적으로 할 수있는 최악의 일이 있다는 것을 알고,하지만 난 더 나은 방법을 생각할 수 없다. "에 ValueError : 너무 많은 값을 풀고"일을 속도를
map = np.zeros((1024,1024))
for i,j in map:
x = independent_variable # This is my independent variable
y = spec_cube[:,i,j] # The Y data to be fitted is the power at each scale, for a pixel
index = polyfit(x,y,1) # Outputs the slope and the offset
map[i,j] = index[0] # The pixel value is the index
이 질문과 관련 질문은 파이썬/numpy의 일반적인 문제점을 보여줍니다. 내부 루프가 꽉 찼기 때문에 numpy 벡터 연산이 없으면 최적화하는 데 아무리 어려움이 있더라도 본질적으로 문제가됩니다. 이러한 유형의 사례에서는 C- 확장 또는 더 나은 아직 Cython과 같은 다른 대안을 진지하게 고려해야합니다. –