如何将 odeint 中的数组作为时间相关参数进行索引

问题描述

我正在尝试将一个数组作为 odeint 函数中的参数进行索引,例如这个数组:

H_lookup = np.array([1,2,3,4,5])

我使用的函数是:

def deriv_new(y,t,delta,p_I_to_H):
I = y
dIdt = (H_lookup[t] / (delta * p_I_to_H))
return dIdt

给出错误

IndexError: only integers,slices (`:`),ellipsis (`...`),numpy.newaxis (`None`) and integer or boolean arrays are valid indices

所以我的解决方案一直试图绕过 t:

def deriv_new(y,p_I_to_H):
I,E,T = y
dIdt = (H_lookup[t] / (delta * p_I_to_H))
dEdt = -E + H_lookup[round(t)]
dTdt = -T + round(t)
return dIdt,dEdt,dTdt

作为实验,我尝试了额外的输出,例如 dEdt(我期望在 t0 - t5 之后的 H_lookup)和 dTdt(我期望在 t0 - t5 之间的 t)。但我的结果是:

(array([0.,1.,2.,3.,4.]),array([10218.,13083.24944302,17858.66517239,24544.24716474,33139.99537782]),array([1.,1.39346935,2.17033918,3.08825417,4.05805678]),array([0.,0.39346935,1.17033918,2.08825417,3.05805678]))

我的意见没有意义,因为我期望 t0-t5 和 H_lookup 1-5 都是整数而不是浮点数。

我知道我可能不理解 odeint 的一个关键函数,因为 t 不是以 1 为单位变化的。但是当 t 不是最佳选择时,我如何才能最好地索引 odeint 函数中的数组?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)