【问题标题】:Making array matrix with minimal code in IDL在 IDL 中用最少的代码制作数组矩阵
【发布时间】:2018-07-10 01:57:32
【问题描述】:

我是 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)

我该怎么做?

【问题讨论】:

    标签: idl-programming-language


    【解决方案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)
    

    【讨论】:

      猜你喜欢
      • 2019-08-10
      • 1970-01-01
      • 2013-03-09
      • 1970-01-01
      • 2020-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多