Float and scipy: Problem solved, but comments welcome

300 views
Skip to first unread message

Thomas Ligon

unread,
Mar 4, 2022, 11:44:34 AM3/4/22
to sympy
I am using  scipy.optimize.minimize_scalar and got an error:
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\site-packages\scipy\optimize\_minimize.py", line 873, in minimize_scalar
    return _minimize_scalar_bounded(fun, bounds, args, **options)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\site-packages\scipy\optimize\_optimize.py", line 2210, in _minimize_scalar_bounded
    if np.isnan(xf) or np.isnan(fx) or np.isnan(fu):
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

After changing the return of my objective function from 
retVal = abs(q1In - PSq1IC(maxk, x)) to
retVal = float(abs(q1In - PSq1IC(maxk, x)))
things are working well.
My conclusion: scipy.optimize.minimize_scalar can deal with float and float64, but not Float.
Reply all
Reply to author
Forward
0 new messages