ufunc'subtract'不包含签名匹配类型为(dtype('<U32'),dtype('<U32'))-> dtype('<U32')的循环

时间:2020-07-14 22:11:30

标签: python arrays numpy matrix emcee

我试图将两个矩阵相减,首先使用np.substract,然后简单地使用“-”。矩阵减法的代码工作得很好,但是当我向函数输入相同的代码时,python给出了此错误

Traceback (most recent call last):
  File "C:\Users\ASUS\anaconda3\lib\site-packages\emcee\ensemble.py", line 545, in __call__
    return self.f(x, *self.args, **self.kwargs)
  File "<ipython-input-95-627a7e4792e9>", line 11, in logposterior
    return lp +  log_likelihoodboss(theta, dataHd, covariance, BOSSDR12_z)
  File "<ipython-input-94-8ffe5ede0b1c>", line 15, in log_likelihoodboss
    ymu= dataHd-matriksmodel
numpy.core._exceptions.UFuncTypeError: ufunc 'subtract' did not contain a loop with signature matching types (dtype('<U32'), dtype('<U32')) -> dtype('<U32')

这是可能性

def log_likelihoodboss(theta, dataHd, covariance, BOSSDR12_z):
    A, B, C, D, epsilon, rd= theta
    Hfid = 67.
    rd_fid = 147.78
    teori = []
    for i in range(len(BOSSDR12_z)):
        H = Hfid*(A*(1+BOSSDR12_z[i])**3 + B + C*BOSSDR12_z[i] +   D*(1+BOSSDR12_z[i])**epsilon)**0.5
        integral = integrate.quad(lambda x: 1/H, 0, BOSSDR12_z[i])
        DM = c*integral[0]
        kuantitas1 = DM*(rd_fid/rd)
        teori.append(kuantitas1)
        kuantitas2 = H*rd/rd_fid
        teori.append(kuantitas2)
        matriksmodel= np.array(teori).reshape(6,1)
        ymu= dataHd-matriksmodel
        chisquare= np.dot(np.dot(ymu.T, np.linalg.inv(covariance)), ymu)
        return -0.5 * chisquare

ymu是一个(6,1)矩阵。

0 个答案:

没有答案