gpt4 book ai didi

python - scipy.optimize.leastsq : not a proper array of floats

转载 作者:行者123 更新时间:2023-11-28 18:46:02 24 4
gpt4 key购买 nike

我试图解决一个小玩具问题

import numpy as np
import scipy.optimize as opt

def f(a):
return np.array([a+.2,a-.1])

opt.leastsq(f,2)

但是,它给了我一个错误

\site-packages\scipy\optimize\minpack.py in leastsq(func, x0, args, Dfun, full_output, col_deriv, ftol, xtol, gtol, maxfev, epsfcn, factor, diag)
362 maxfev = 200*(n + 1)
363 retval = _minpack._lmdif(func, x0, args, full_output, ftol, xtol,
--> 364 gtol, maxfev, epsfcn, factor, diag)
365 else:
366 if col_deriv:

error: Result from function call is not a proper array of floats.

但是我的函数 f 确实给出了一个 ndarray。

最佳答案

所以它需要一个类似数组的输入。这有效:

import numpy as np
import scipy.optimize as opt

def f(a):
return np.array([a[0]+.2,a[0]-.1])

print opt.leastsq(f,[2])

关于python - scipy.optimize.leastsq : not a proper array of floats,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20019051/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com