假设
def evaluateFunc(params):
...
return err, grad
其中
params
是由 N
实值组成的向量,err
是实数,grad
是由 2 个实值组成的向量。
params = numpy.random.rand(X.shape[0]+1)
bounds = np.append([(0,None)]*X.shape[0], [(None,None)], axis=0)
当我调用以下函数时
params, minval, infos = fmin_l_bfgs_b(evaluateFunc, params, bounds=bounds)
我收到以下错误:
error: failed in converting 7th argument `g' of _lbfgsb.setulb to C/Fortran array
为什么我会收到该错误?我该如何解决它?
编辑
如果我删除参数
bounds=bounds
,则会出现以下错误:
failed to initialize intent(inout|inplace|cache) array, input not an array
我遇到了类似的问题,结果发现我返回的梯度有dytpe
np.float32
。转换为 np.float64
解决我的问题。