画像の各ピクセルのデータを含むこのデータ キューブがあります (ハイパースペクトル イメージングによく似ています)。効率的な方法で、画像の各ピクセルに線を当てはめようとしています。今、私は次のようにしています:
私のデータキューブは 6X1024x1024 numpy 配列で、データの独立変数を含む別の変数があります。
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
入れ子になった for ループは、一般的には最悪の行為であることはわかっていますが、それ以上の方法は思いつきません。
次のことを試しましたが、次のエラーが表示されます:「ValueError: unpack する値が多すぎます」
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