TypeError:' numpy.ndarray'对象不可调用

时间:2014-07-23 20:38:05

标签: python numpy multidimensional-array distribution emcee

我不知道是否有人熟悉Dan Foreman-Mackley" emcee" Python模块,但我用它来抽样分发。我正在使用Parallel Tempering采样器,因为我的发布看起来很时髦。以下是相关代码:

from emcee import PTSampler

rendim = 6
renwalkers = 100
ntemps = 20


gauss2 = PTSampler(ntemps, renwalkers, rendim, lnlike, lnprior)

p0 = [[[np.random.rand()*0.24,np.random.rand()*3,np.random.rand()*1,np.random.rand()*1,np.random.rand()*3,np.random.rand()*1] for i in range(renwalkers)] for i in range(ntemps)]

for q, lnprob, lnlike in gauss2.sample(p0,iterations=1000):
    pass
gauss2.reset()

for q, lnprob, lnlike in gauss2.sample(p, lnprob0=lnprob,
                                       lnlike0=lnlike,
                                       iterations=10000, thin=10):
    pass

我不断收到“numpy.ndarray'对象不可调用。这是完整的错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-25-d5f2a1f4b7b0> in <module>()
     11 p0 = [[[np.random.rand()*0.24,np.random.rand()*3,np.random.rand()*1,np.random.rand()*1,np.random.rand()*3,np.random.rand()*1] for i in range(renwalkers)] for i in range(ntemps)]
     12 
---> 13 for q, lnprob, lnlike in gauss2.sample(p0,iterations=1000):
     14     pass
     15 gauss2.reset()

/Library/Python/2.7/site-packages/emcee-2.1.0-py2.7.egg/emcee/ptsampler.py in sample(self, p0, lnprob0, lnlike0, iterations, thin, storechain)
    255                              self.logpargs, self.loglkwargs, self.logpkwargs)
    256             if self.pool is None:
--> 257                 results = list(map(fn, p.reshape((-1, self.dim))))
    258             else:
    259                 results = list(self.pool.map(fn, p.reshape((-1, self.dim))))

/Library/Python/2.7/site-packages/emcee-2.1.0-py2.7.egg/emcee/ptsampler.py in __call__(self, x)
     94             return lp, lp
     95 
---> 96         return self.logl(x, *self.loglargs, **self.loglkwargs), lp
     97 
     98 

TypeError: 'numpy.ndarray' object is not callable

更新:这里是lnlike和lnprior函数:

def lnprior(theta):
    eta, mu1, sig1, h, mu2, sig2 = theta
    if 0 < eta < 0.24 and 0 < mu1 < 1.5 and 0 < sig1 < 1 and 0 < h < 1 and 0 < mu2 < 1.5 and 0 < sig2 < 1:
        return 0
    return -np.inf

def lnlike(theta):
    eta, mu1, sig1, h, mu2, sig2 = theta
    return -k*np.log(Nsamp)+np.sum(np.log(np.sum(MCetadist(eta,events,mu1,sig1,h,mu2,sig2),axis=1)))

1 个答案:

答案 0 :(得分:-2)

消息“TypeError:'numpy.ndarray'对象不可调用”意味着您尝试作为函数调用的“numpy.ndarray”是一个模块或变量,因此不可调用。当您使用'()'调用非函数时,您将遇到此类型错误。您可以在该引用之后删除'()',一切都会好的。