简体   繁体   中英

ValueError: too many values to unpack in fmin_l_bfgs_b

I have the following code that is running to run xfoil to get me optimum values of weights in an aerofoil.

def four_dim_opt(x0, weight_limits, cl, file_path, xfoil_path):
opt_out = fmin_l_bfgs_b(run_xfoil_wcl, x0, args = (cl, file_path, xfoil_path), bounds =    weight_limits, epsilon = 0.01, approx_grad = True)
return opt_out

where run_xfoil_wcl is a functionreturning coefficient of drag values (float).

The error I keep getting is:

Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
four_dim_opt(x0, weight_limits, 1.2, file_path, xfoil_path)
File "H:/appliedlab4 - Copy(2).py", line 157, in four_dim_opt
opt_out = fmin_l_bfgs_b(run_xfoil_wcl, x0, args = (cl, file_path, xfoil_path), bounds =     weight_limits, epsilon = 0.01, approx_grad = True)
File "C:\Python27\lib\site-packages\scipy\optimize\lbfgsb.py", line 166, in fmin_l_bfgs_b
l,u = bounds[i]
ValueError: too many values to unpack

The weight_limits argument to scipy.optimize.fmin_l_bfgs_b is causing the error and it should be either None or a list containing two elements:

weight_limits - (min, max) pairs for each element in x, defining the bounds on that parameter. Use None for one of min or max when there is no bound in that direction.

What are you passing to four_dim_opt as your weight_limits ? The value for weight_limits gets passed to bounds, which is then accessed in the line in your error message:

l,u = bounds[i]

This means weight_limits is expected to be a list or tuple, and each item in the list should ALSO be a list or tuple (holding exactly two values).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM