Python 运行scipy优化会产生属性错误

Python 运行scipy优化会产生属性错误,python,Python,我正在尝试使用scipy optimize和minimize函数来查找我的两个猜测变量的值,这两个变量使函数最小化,我目前正在这样运行它: def function_to_min(theta): respons = responsibilities()[0][0][0] sequence_to_foc = sequence[0][0][0] pis = calculating_pis()[0] return np.nan_to_num((-1)*(respons

我正在尝试使用scipy optimize和minimize函数来查找我的两个猜测变量的值,这两个变量使函数最小化,我目前正在这样运行它:

def function_to_min(theta):
    respons = responsibilities()[0][0][0]
    sequence_to_foc = sequence[0][0][0]
    pis = calculating_pis()[0]
    return np.nan_to_num((-1)*(respons * np.log(pis*get_emission(theta[0], sequence_to_foc, theta[1]))))

theta2 = np.array([mu_initial2, sigma_guess])

res = minimize(function_to_min, theta2, method='nelder-mead',
options = {'xtol': 2, 'disp': True})
print(res.theta)
我还没有发布所有的代码,我可以打印值的结果,所有的内容都是单值的(没有数组)。为什么我总是得到加薪属性错误(姓名)
AttributeError:theta?

我想代码末尾的res.theta会导致这种情况。根据scipy文件。optimize的返回为docs.scipy.org/doc/scipy/reference/generated/…。这意味着你应该改为打印(res.x)。

代码末尾的
res.theta
,我想这就是原因。根据scipy文件。优化的回报是。这意味着你应该
print(res.x)
而不是说你是对的,这解决了我的问题,我很感谢你的帮助,但我个人的自尊心像一记重拳。。。非常感谢你的帮助!