我是IDL的新手。我想最小化代码。我正在写这个
for x=0,(pixel-1) do begin
for y=0,(pixel-1) do begin
for z=0,(pixel-1) do begin
Bx[x,y,z]=-(n*3.14/pixel)*cos(n*3.14*x/pixel)*sin(m*3.14*y/pixel)*exp(-sqrt(n^2+m^2)*3.14*z/pixel)
endfor
endfor
endfor
我想简化为
x=dindgen(pixel)
y=dindgen(pixel)
z=dindgen(pixel)
Bx[x,y,z]=-(n*3.14/pixel)*cos(n*3.14*x/pixel)*sin(m*3.14*y/pixel)*exp(-sqrt(n^2+m^2)*3.14*z/pixel)
我该怎么办?
答案 0 :(得分:1)
根据pixel
的大小,您可能无法创建以下数组:
x = rebin(reform(dindgen(pixel), pixel, 1, 1), pixel, pixel, pixel)
y = rebin(reform(dindgen(pixel), 1, pixel, 1), pixel, pixel, pixel)
z = rebin(reform(dindgen(pixel), 1, 1, pixel), pixel, pixel, pixel)
但如果可以,您应该可以:
Bx = -(n*3.14/pixel)*cos(n*3.14*x/pixel)*sin(m*3.14*y/pixel)*exp(-sqrt(n^2+m^2)*3.14*z/pixel)