odepack.error: Extra arguments must be in a tuple(odepack.error:额外的参数必须在一个元组中)
问题描述
我的 ode 求解器遇到了一些问题,我正在尝试解决 SEIR 问题,尽管我的代码基于非常相似的代码,但我不断收到相同的错误.我的代码是:
I'm having some issues with my ode solver, I am trying to solve an SEIR problem and I keep getting the same errors dispite the code that i have based my code on being very similar. My code is:
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
# Total population, N.
N1 = 55600
# Initial number of infected and recovered individuals, I0 and R0.
I10, R10, E10 = 1, 0, 0
# Everyone else, S0, is susceptible to infection initially.
S10 = N1 - I10 - R10 - E10
# parameters
B = 0.05
a = 0.000001
d = 0.0167
g = 0.0167
z = 0.0167
M = 100000
# A grid of time points (in months)
t = np.linspace(0, 160, 160)
# The SIR model differential equations.
def deriv(y, t, N1, B, a, d, g, z, M):
S1, E1, I1, R1 = y
dS1dt = B*N1 + d*(R1) - S1/N1 * (M*a(I1))
dE1dt = S1/N1 * M*a(I1) - g * E1
dI1dt = g * E1 - z * I1
dR1dt = z * I1 - d * R1
return dS1dt, dE1dt, dI1dt, dR1dt
# Initial conditions vector
y0 = S10, E10, I10, R10
# Integrate the SIR equations over the time grid, t.
ret = odeint(deriv, y0, t, args=[N1, B, a, d, g, z, M])
S1, E1, I1, R1 = ret.T
我不断收到错误:
文件C:/Users/Angus/PycharmProjects/firstAttempt/bugfinder.py",第 44 行,在
File "C:/Users/Angus/PycharmProjects/firstAttempt/bugfinder.py", line 44, in
ret = odeint(deriv, y0, t, args=[N1, B, a, d, g, z, M],)
文件C:Python36libsite-packagesscipyintegrateodepack.py",第 215 行,在 odeintixpr, mxstep, mxhnil, mxordn, mxords)odepack.error: 额外的参数必须在一个元组中
File "C:Python36libsite-packagesscipyintegrateodepack.py", line 215, in odeint ixpr, mxstep, mxhnil, mxordn, mxords) odepack.error: Extra arguments must be in a tuple
任何帮助将不胜感激!
推荐答案
尝试替换:
ret = odeint(deriv, y0, t, args=[N1, B, a, d, g, z, M],)
这样:
ret = odeint(deriv, y0, t, args=(N1, B, a, d, g, z, M))
来自 scipy 文档:
args : 元组,可选
args : tuple, optional
传递给函数的额外参数.
Extra arguments to pass to function.
此外,谷歌 差异 b/w 列表和元组.
这篇关于odepack.error:额外的参数必须在一个元组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:odepack.error:额外的参数必须在一个元组中
- 我如何卸载 PyTorch? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01