输入错误:' builtin_function_or_method'对象没有属性' __ getitem __'

时间:2018-06-11 17:42:13

标签: python

def FindBestGamma(u,DLx,DLy,DLcon,x0,y0,t,sigmax0,sigmay0,varinterval):
    u=5
    g = np.linspace(0.,1.,u)
    gammaPossible = np.array([seq for seq in itertools.product(g, repeat=u-1) if abs(sum(seq) - 1.0) < 1.0e-4])
    i = 0
    lv = []
    while i < len(gammaPossible):
        L = []
        j = 0
        while j < 1000:
            var = np.array(sampler(varinterval).next())
            tmp =LV(DLx[i],DLy[i],DLcon[i],gammaPossible[i],var,x0,y0,t,sigmax0,sigmay0)
            L.append(tmp)
            j = j+1
        lv.append(max(L))
        i = i+1
    # return np.argmax(np.array(lv))#
    gamma = gammaPossible[np.argmax(np.array(lv))]
    return gamma

def forwd(x,y,gamma,var,x0,y0,t,sigmax0,sigmay0):
    [mux1,muy1,sigmax1,sigmay1,rho1,mux2,muy2,sigmax2,sigmay2,rho2,mux3,muy3,sigmax3,sigmay3,rho3,mux4,muy4,sigmax4,sigmay4,rho4] = var
    return gamma[0]*ff(x,y,mux1,muy1,sigmax1,sigmay1,rho1,x0,y0,t,sigmax0,sigmay0) + gamma[1]*ff(x,y,mux2,muy2,sigmax2,sigmay2,rho2,x0,y0,t,sigmax0,sigmay0) + gamma[2]*ff(x,y,mux3,muy3,sigmax3,sigmay3,rho3,x0,y0,t,sigmax0,sigmay0) + gamma[3]*ff(x,y,mux4,muy4,sigmax4,sigmay4,rho4,x0,y0,t,sigmax0,sigmay0)

这是我的代码中的一个部分的示例。每当我尝试运行整个代码时,我都会收到错误:&#39; builtin_function_or_method&#39;对象没有属性&#39; getitem &#39;在我的def forwd部分。我认为这与伽马计算有关,因为当我通过给出一个像gamma=[0.0,0.0,0.25,0.75]这样的集合数组来测试代码时,代码可以工作。如何修复代码以防止转发部分中的错误?

File "/Users/maryjacketti/Desktop/SOSim/sunkunoil/s4.py", line 71, in integ
    return forwd(x,y,gamma,var,x0new,y0new,t,sigmax0,sigmay0)*LV(DLx,DLy,DLcon,gamma,var,x0,y0,tt,sigmax0,sigmay0)
  File "/Users/maryjacketti/Desktop/SOSim/sunkunoil/s4.py", line 49, in forwd
    return gamma[0]*ff(x,y,mux1,muy1,sigmax1,sigmay1,rho1,x0,y0,t,sigmax0,sigmay0) + gamma[1]*ff(x,y,mux2,muy2,sigmax2,sigmay2,rho2,x0,y0,t,sigmax0,sigmay0) + gamma[2]*ff(x,y,mux3,muy3,sigmax3,sigmay3,rho3,x0,y0,t,sigmax0,sigmay0) + gamma[3]*ff(x,y,mux4,muy4,sigmax4,sigmay4,rho4,x0,y0,t,sigmax0,sigmay0)
TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'

这是我得到的错误。

0 个答案:

没有答案