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

  • Home
  • SEARCH
  • 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 4023832
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:38:48+00:00 2026-05-20T10:38:48+00:00

I’m relatively new to python, have done it a bit for my physics university

  • 0

I’m relatively new to python, have done it a bit for my physics university course.

At the moment I’m trying to write a program to calculate some stuff to do with vector functions, that’s not really important though as I have it all working up until the last section.

The program up to this point produces a load of local minima on a 2D graph, however I need to find the minimum value overall.

for i in range(100):
    pyplot.xlim(x0, x1) # x0, y0 etc are constants defined before in global scope
    pyplot.ylim(y0, y1)
    pyplot.plot(min_points[:,0], min_points[:,1])
    x, y = random.uniform(x0, x1), random.uniform(y0, y1)
    min_points = gradient_descent((x,y)) # gradient_descent is function used

    xmin_list, ymin_list = [], [] # now to find overall minima, initialise list
                                  # of local minima, and append those that are within
                                  # the boundaries
    if x0 < min_points[-1, 0] < x1:
        if y0 < min_points[-1, 1] < y1:

            xmin_list.append(min_points[-1, 0])
            ymin_list.append(min_points[-1, 1])

    xmin, ymin = xmin_list[0], ymin_list[1] # < error comes in this line 

I’ve included the rest of the big for loop below for completeness, but it’s not the bit giving me an error (yet).

    for ix in range(len(xmin_list)):
        for iy in range(len(ymin_list)):
            if f((xmin_list[ix], ymin_list[iy])) < f((xmin, ymin)):
                xmin, ymin = xmin_list[ix], ymin_list[iy]

So it’s clearly something around the middle of the whole loop, but I’m not sure why I’m getting the error. I’m trying to access the last elements of each list, then append them to the list (after checking for fitting the conditions x0, x1 etc).

I’m not sure why it’s not working..

I’m also sure this is a fairly complex way of going about finding the minimum, but it seemed logical to me, and I get confused easily having to do extra things like check they’re within the boundaries etc.

Thanks for any help! And yes I’m also sure my coding looks horrible and messy, but I’ll tidy it up after I get it working (they’re not very good at teaching us style, only function..)

EDIT: Sorry, forgot to post the error exactly, here it is:

Traceback (most recent call last):
  File "filepath etc etc", line 67, in <module>
    xmin, ymin = xmin_list[0], ymin_list[1]
IndexError: list index out of range
  • 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-05-20T10:38:49+00:00Added an answer on May 20, 2026 at 10:38 am
    xmin, ymin = xmin_list[0], ymin_list[1] # < error comes in this line 
    

    The error here is the [1]. If the preceding if statement conditions are False, then ymin_list is still the empty list you set it to, and index 1 is past the end.

    Also, in the second part you don’t need to be using range(len()) like that. Try:

    xmin = xmin_list[0]
    ymin = ymin_list[0]
    vmin = f((xmin, ymin))
    for x in xmin_list:
        for y in ymin_list:
            v = f((x, y))
            if v < vmin:
                xmin = x
                ymin = y
                vmin = v
    

    … Come to think of it, are you initializing xmin and ymin?

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

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

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.