Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8390123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:54:13+00:00 2026-06-09T18:54:13+00:00

I am using the Scipy optimization module, specifically fmin_tnc and fmin_l_bfgs_b . However, I

  • 0

I am using the Scipy optimization module, specifically fmin_tnc and fmin_l_bfgs_b. However, I am receiving the message “IndexError: invalid index to scalar variable” when using either one.

What is the cause of this error?

And what is the meaning of this error message?

My practice code:

def f01(para):
    para1, para2 = para
    return 1+ (para1 -1)**2 + (para2 -2)**2

para0 = np.array([10, 10]) 
mybounds = [(-40,30),(-20,15)]

opt.fmin_l_bfgs_b(f01, para0,  bounds = mybounds )

Which returns:

Traceback (most recent call last):
  File "C:\Python27\mystuff\practice_optimize01.py", line 78, in <module>
    opt.fmin_l_bfgs_b(f01, para0,  bounds = mybounds )

  File "C:\Python27\lib\site-packages\scipy\optimize\lbfgsb.py", line 174, in fm
in_l_bfgs_b
**opts)

  File "C:\Python27\lib\site-packages\scipy\optimize\lbfgsb.py", line 294, in _m
 inimize_lbfgsb
    f, g = func_and_grad(x)

  File "C:\Python27\lib\site-packages\scipy\optimize\lbfgsb.py", line 249, in fu
nc_and_grad
    f = fun(x, *args)

  File "C:\Python27\lib\site-packages\scipy\optimize\optimize.py", line 55, in _
_call__
    self.jac = fg[1]
IndexError: invalid index to scalar variable.

Python 2.7.3, 32-bit.
Numpy 1.6.2.
Scipy 0.11.0b1.
Windows XP and Vista.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:54:14+00:00Added an answer on June 9, 2026 at 6:54 pm

    fmin_l_bfgs_b expects that your function returns the function value and the gradient. You return only the function value.

    If you only return the function value and don’t provide a gradient, then you need to set approx_grad=True so that fmin_l_bfgs_b uses a numerical approximation to it.

    See the description of the options in the docstring.

    From my reading of the documentation, fmin_tnc has the same pattern, and same problem in your case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using scipy.optimize 's fmin I'm getting an error I don't understand: ValueError: setting
I'm using scipy.linalg to solve a matrix equation A*x = b The following code
I am using Scipy to construct a large, sparse (250k X 250k) co-occurrence matrix
I am using scipy-cluster in my application. It provides a function to plot a
I am trying to do a fit to a given function using Scipy. Scipy.optimize.leastsq
I have been using the scipy.stats.invgamma.rvs function to randomly select values from an inverse
i am using this: http://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html i have an list a that i want to
When testing scipy using the nose package using scipy.test() , the test fails under
I am currently using scipy's linregress function for single regression. I am unable to
I'm trying to compute the laplacian of a 2d field A using scipy.ndimage.convolve .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.