Python错误消息:

2024-04-27 14:54:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图写这个代码,但我不断得到这个错误消息,我不知道如何修复它

Pmdl=(wexctoinhibint(Pexc))-(winhibtomdlint(Pinhib))

TypeError:int()参数必须是字符串、类似字节的对象或数字,而不是“list”

有人知道怎么解决这个问题吗?非常感谢! 代码如下:

from scipy import array, linspace
from scipy import integrate
from matplotlib.pyplot import *
from math import exp, tanh
from numpy import *

def Temp2(z, t, Ta, Te, wexc, yexc, winhib, yinhib, whd, yhd, wexctoinhib, 
winhibtomdl, whdtospn, yspn, Tt):

# Dependence of Meth Concentration 
#
#    dx
#    -- = -x/Ta
#    dt
#
#    dy
#    -- = x/Ta - y/Te
#    dt
# x = interperitoneal 
# y = blood
# Ta is the time constant of Meth in the absorbtion
# Te is the time constant of Meth in elimination
x = z[0] # Rabbits density
y = z[1] # Sheep density
T = z[2]
D = float(x=1)
yt = D*(Ta/Te-1)**-1 * (exp(-t/Ta) - exp(-t/Te))
act = int(tanh(z[0]))
Pexc = (1+act)*(wexc*yt*yexc)
print(Pexc)
Pinhib = (1+act)*[winhib*yt*yinhib]
print(Pinhib)
Phd = (1+act)*[whd*yt*yhd]
print(Phd)
Pmdl = (wexctoinhib*int(Pexc))-(winhibtomdl*int(Pinhib)) 
print(Pmdl)
Pspn = Pmdl + whdtospn*Phd+yspn
print(Pspn)
V = array([-x/Ta, x/Ta - y/Te, (Pspn-(T-T0))/Tt])
return V


def main():
# set up our initial conditions
IC0 = 1
BC0 = 0
T0 = 37

z0 = array([IC0, BC0, T0])

# Parameters
Ta = 8.25
Te = 57.5
wexc = 1.225
yexc = -0.357
winhib = 1.335
yinhib = 1.463
whd = 0.872
yhd = -3.69
wexctoinhib = 7.47
winhibtomdl = 6.38
whdtospn = 5.66
yspn = -3.35
Tt = 89.2

# choose the time's we'd like to know the approximate solution
t = linspace(0., 1., 60)

# and solve
xode= integrate.odeint(Temp2, z0, t, args=(Ta, Te,  wexc, yexc, winhib, yinhib, whd, yhd, wexctoinhib, winhibtomdl, whdtospn, yspn, Tt))
print (xode)

#    # now, plot the solution curves
#    figure(1)
#    plot(t, xode[:,0], 'b-', linewidth=2)
#    plot(t, xode[:,1], 'g-', linewidth=2)
#    #axis([0,240,30, 40])
#    xlabel('Time (min)')
#    ylabel('Concentration of Meth in Organism')
#    title('Concentration of Meth in the Male Rats vs. Time')
#    legend(['1 mg/kg', '3 mg/kg', '5 mg/kg', '10 mg/kg'], loc=2, framealpha=0.)
#    tight_layout()
#    savefig('Male Rats and Meth.png',transparent=True)
#    show()

main()

Tags: ofthefromimportintprintteta
1条回答
网友
1楼 · 发布于 2024-04-27 14:54:32

在此行中:

Pinhib = (1+act)*[winhib*yt*yinhib]

你用的是方括号而不是圆括号。对于复杂的数学方程/运算顺序,只需使用嵌套的圆括号,因此该行将变为:

Pinhib = (1+act)*(winhib*yt*yinhib)

[]表示列表和非列表,它将Pinhib转换为其他类型(列表!)

此代码:

x = 5
y = 1
print(type(x))
print(type(y))
temp = (1+2)*[x*y]
print(type(temp))

结果如下:

<class 'int'>
<class 'int'>
<class 'list'>

如果你对自己所使用的类型感到困惑,只需大量地使用type(yourVariable),你就可以剔除那些被转换成其他类型的内容

相关问题 更多 >