In order to minimize the function with variable constraints, we specified L-BFGS-B in scipy.optimize.minimize as follows.
import scope.optimize as opt
bound=opt.Bounds(#np.ndarray, #np.ndarray)
result=opt.minimize(loss_f,x0_ft,method='L-BFGS-B',jac=f_grad,
bound=bound, toll=10e-6, options={'maxiter':100, 'disp':True})
At this time, an failed to initialize int(inout) array --expected elsize=8 butgot4
error occurs and cannot be executed
method
can run correctly if you specify something else, and this error only occurs when you use L-BFGS-B
If anyone knows how to solve it, please let me know
python 3.6.8
scipy: 1.3.0
Output below
RUNNING THE L-BFGS-BCODE
* * *
Machine precision = 2.220D-16
N = 9 M = 10
At X00 variables are exactly at the boundes
# Standard output up to this point
# Error output from here
Traceback (most recent call last):
File "main.py", line 147, in<module>
main()
File "main.py", line 120, in main
options={'maxiter':100, 'disp':True})
File "Abbreviated /scipy/optimize/_minimize.py", line 600, in minimize
callback=callback,**options)
File "Abbreviated /scipy/optimize/lbfgsb.py", line328, in_minimize_lbfgsb
isave, dsave, maxls)
ValueError: failed to initialize int(inout) array --expected elsize=8 but got4
Self-resolved. The target function and its gradient return function loss_f
, f_grad
returned np.float32
, but I tried to return np.float64
, and I was able to execute it.
Then I think the error elseize
meant the number of bytes.
It's a symptomatic solution, but just for your information.
© 2025 OneMinuteCode. All rights reserved.