亲爱的 friend ,我在运行Python后发送了错误代码,并编写了大量代码:
抱歉,这个问题是业余的。
dacdm = 1/(z+1) * cdm
TypeError: 'numpy.float64' object cannot be interpreted as an integer
这是错误的最后2句话。 Python错误地提到了我的代码的以下部分,因此我确定错误来自此处:
def H_LCDM(z, H0, DM0):
lcdm = 1/(H0 * sqrt(DM0 * (1 + z)**3 + (1 - DM0)))
return lcdm
def DA_LCDM(z, DM0, H0):
cdm = quad(H_LCDM, 0, z, args = (H0, DM0))
dacdm = 1/(z+1) * cdm
return dacdm
def fg(gg, DM0, H0, A, alpha, b, Omb):
h = H0/100
f_th = (0.824 /(1 + 0.19 * (h)**(1/2)))* (Omb/DM0) * (DA_LCDM(zgas[gg], H0, DM0)/DA(zgas[gg], DM0, H0, A, alpha, b))
fgasth = ((fgas[gg] - f_th)/siggas[gg])**2
return fgasth
def fgasmass(DM0, H0, A, alpha, b, Omb):
h = H0/100
num=0
for gsgs in range(len(zgas)):
num = num + fg(gsgs, DM0, H0, A, alpha, b, Omb)
return num + ((Omb * h**2 - 0.0214)/0.002)**2 + ((h - 0.72)/0.08)**2
我无法找到问题的根源。
有关更多信息,我将整个错误放在这里:
Traceback (most recent call last):
File "C:\Users\esadr21\Desktop\Polytropic\Polytropic datasets.py", line 348, in <module>
L = np.exp(-0.5 * (TOTAL(DM0n[i], H0n[i], An[i], alphan[i], bn[i], Mn[i], Ombn[i]) - TOTAL(DM0o[i-1], H0o[i-1], Ao[i-1], alphao[i-1], bo[i-1], Mo[i-1], Ombo[i-1]))) # L = exp(-( x^2 )/2)
File "C:\Users\esadr21\Desktop\Polytropic\Polytropic datasets.py", line 328, in TOTAL
total = SN(DM0, H0, A, alpha, b, M) + BAO(DM0, H0, A, alpha, b, Omb) + CMB(Omb, H0, DM0, A, alpha, b) + CC(DM0, H0, A, alpha, b) + SGL(DM0, H0, A, alpha, b) + fgas(DM0, H0, A, alpha, b, Omb)
File "C:\Users\esadr21\Desktop\Polytropic\Polytropic datasets.py", line 322, in fgas
num = num + fg(gsgs, DM0, H0, A, alpha, b, Omb)
File "C:\Users\esadr21\Desktop\Polytropic\Polytropic datasets.py", line 315, in fg
f_th = (0.824 /(1 + 0.19 * sqrt(h)))* (Omb/DM0) * (DA_LCDM(zgas[gg], H0, DM0)/DA(zgas[gg], DM0, H0, A, alpha, b))
File "C:\Users\esadr21\Desktop\Polytropic\Polytropic datasets.py", line 163, in DA_LCDM
dacdm = 1/(z+1) * cdm
TypeError: 'numpy.float64' object cannot be interpreted as an integer
非常感谢。
最佳答案
cdm
是一个序列,而不是数字。 quad
可能是 scipy.integrate.quad
,它返回一个最多包含5个元素的元组,而不仅仅是一个整数。带有序列的*
期望一个整数,该整数表示重复该序列的次数;例如,我们有
>>> 3 * (1, 2, 3)
(1, 2, 3, 1, 2, 3, 1, 2, 3)
如果
quad
是scipy.integrate.quad
,则积分是元组的第一个元素,因此,如果需要积分,请从结果中索引它:# vvv
cdm = quad(H_LCDM, 0, z, args = (H0, DM0))[0]
另外,将来,请阅读文档以获取使用的功能。
关于python - 集成导致TypeError : 'numpy.float64' object cannot be interpreted as an integer,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52655681/