Curve拟合错误-索引错误:只有整数,切片(`:`),省略号(`...`),numpy.newaxis(`None`)和整数或布尔数组是有效的索引。

2024-06-28 19:02:13 发布

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

试图拟合一个简化的Bloch-Grüneisen曲线。Python不是最好的,所以有点乱。在

在曲线拟合之前,一切似乎都很好,我得到了错误信息:

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

import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate as sc
from scipy.optimize import curve_fit
import scipy.constants as spc
import scipy as spy
Cu_2000A=np.genfromtxt('Cu_2000A.txt')
R = Cu_2000A[:,0]
T = Cu_2000A[:,1]

ylist = []   
def Bloch1(T,k,debye):
    for Tval in np.nditer(T):
        yval = float((k*(Tval/debye)**5))
        ylist.append(yval)

    return ylist
xlist = []
def Integrate(debye):
    for Tval in np.nditer(T):
        xval =(sc.quad(lambda x: ((x**5)/(((np.exp(x))-1)*(1-(np.exp(-x))))), 0, (debye/(Tval))))
        xlist.append(float(xval[0]))

    return xlist
def Bloch(T, R0, k, debye):
    test = np.asarray(Bloch1(T, k, debye))
    test2 = np.asarray(Integrate(debye))

    return (R0 + (test*test2))



popt, pcov = curve_fit(Bloch, T, R [0.1, 1000, 350])

Tags: importnumpyreturndefasnpscipybloch