python 中的 IDL?
IDL WHERE in python?
我在将旧的 IDL 脚本转换为 python 时遇到问题 - 我的问题在于准确理解如何解释 IDL 的 "WHERE" 函数。
这是我的代码:
FUNCTION noise,day,y
N = N_ELEMENTS(y)
valid = WHERE(ABS(day[0:N-3]-day[2:N-1]) LT 20,cc)
IF cc LT 2 THEN RETURN,[-9.99,-9.99,-9.99,-9.99]
y_int = (y[0:N-3] * (day[2:N-1] - day[1:N-2]) + y[2:N-1] * (day[1:N-2] - day[0:N-3]))/ (day[2:N-1] - day[0:N-3])
dif = ABS(y_int - y[1:N-2])
difR = ABS(y_int/y[1:N-2] - 1.)
dif = dif [valid]
difR= difR[valid]
; Remove 5% of higher values
Nv = LONG(cc*0.95)
s = SORT(dif) & s = s[0:Nv-1]
noise5 = SQRT(TOTAL(dif[s]^2)/(Nv-1)) ; Absolu Noise minus 5% of higher values
noise = SQRT(TOTAL(dif^2)/(cc-1)) ; Absolu Noise
s = SORT(difR) & s = s[0:Nv-1]
noiseR5 = SQRT(TOTAL(difR[s]^2)/(Nv-1)) ; Relative Noise minus 5% of higher values
noiseR = SQRT(TOTAL(difR^2)/(cc-1)) ; Relative Noise
RETURN,[noise5,noiseR5*100.,noise,noiseR*100.]
END
任何人都可以帮助我理解 python 等价物吗? TY.
我会翻译:
valid = WHERE(ABS(day[0:N-3]-day[2:N-1]) LT 20,cc)
如:
valid = (numpy.abs(day[0:-2] - day[2:]) < 20).nonzero()
我在将旧的 IDL 脚本转换为 python 时遇到问题 - 我的问题在于准确理解如何解释 IDL 的 "WHERE" 函数。
这是我的代码:
FUNCTION noise,day,y
N = N_ELEMENTS(y)
valid = WHERE(ABS(day[0:N-3]-day[2:N-1]) LT 20,cc)
IF cc LT 2 THEN RETURN,[-9.99,-9.99,-9.99,-9.99]
y_int = (y[0:N-3] * (day[2:N-1] - day[1:N-2]) + y[2:N-1] * (day[1:N-2] - day[0:N-3]))/ (day[2:N-1] - day[0:N-3])
dif = ABS(y_int - y[1:N-2])
difR = ABS(y_int/y[1:N-2] - 1.)
dif = dif [valid]
difR= difR[valid]
; Remove 5% of higher values
Nv = LONG(cc*0.95)
s = SORT(dif) & s = s[0:Nv-1]
noise5 = SQRT(TOTAL(dif[s]^2)/(Nv-1)) ; Absolu Noise minus 5% of higher values
noise = SQRT(TOTAL(dif^2)/(cc-1)) ; Absolu Noise
s = SORT(difR) & s = s[0:Nv-1]
noiseR5 = SQRT(TOTAL(difR[s]^2)/(Nv-1)) ; Relative Noise minus 5% of higher values
noiseR = SQRT(TOTAL(difR^2)/(cc-1)) ; Relative Noise
RETURN,[noise5,noiseR5*100.,noise,noiseR*100.]
END
任何人都可以帮助我理解 python 等价物吗? TY.
我会翻译:
valid = WHERE(ABS(day[0:N-3]-day[2:N-1]) LT 20,cc)
如:
valid = (numpy.abs(day[0:-2] - day[2:]) < 20).nonzero()