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 70123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:40:53+00:00 2026-05-10T19:40:53+00:00

Here is my sample code. It is meant to be an iterative procedure for

  • 0

Here is my sample code. It is meant to be an iterative procedure for gauss seidel (matrix solver). Essentially when the error is small enough it breaks out of the while loop.

i=1 while (i>0):     x_past = x_present      j=0     while(j<3):         value=0         k=0         while(k<3):             if(k!=j):                 if(i==1):                     if(k>j):                         value=value+0                     else:                         value=value+x_present[k]*eqn[j][k]                     else:                     value=value+x_present[k]*eqn[j][k]             else:                 value=value+eqn[j][k]             k=k+1         x_present[j:j+1]=[value]         j=j+1     print 'X_PAST'     print x_past     print 'X_PRESENT'     print x_present         if(error(x_past, x_present)<10**-2):         break;     i=i+1 

I’ve reduced the code so its more manageable. if you don’t understand what its doing its not really that important to solving this problem.

Here is the issue. Everytime

x_present[j:j+1]=[value] 

is run, x_past is made equal to x_present. I don’t know why this is the case as the only place i have set x_past equal to x_present is at the top of the loop. If I take away the

x_past=x_present 

sentence, x_past is never made equal to x_present. This leads me to think it is some combination of the two statements that is causing the issue.

This is a big problem cause if x_past = x_present the error = 0 every time and the loop breaks after the first iteration. The code does work, for example if I tell the code to run for 8 iterations and the break it gives me the answer its supposed to.

I’ve been trying to figure this out for the last 4 hours and am completely stumped. I haven’t been working with python long, so my trouble shooting skills syntax wise aren’t that great. Any help would be appreciated!!

  • 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. 2026-05-10T19:40:54+00:00Added an answer on May 10, 2026 at 7:40 pm

    Yes, I think the answers here show your problem. Just to try and clarify a little bit.

    You’re referencing a list, so when the list changes any reference to that list will reflect that change. To demonstrate:

    >>> x_present = [4,5,6] >>> >>> x_past = x_present >>> >>> x_past [4, 5, 6] >>> >>> x_present.append(7) >>> >>> x_past [4, 5, 6, 7] >>> 

    If you want a copy of the list you have to do do this, listcopy = mylist[:]. (or import copy;listcopy = copy.copy(mylist)

    >>> x_past = x_present[:] >>> x_past [4, 5, 6, 7] >>> >>> x_present.append(8) >>> >>> x_past [4, 5, 6, 7] 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 85k
  • Answers 85k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would recommend checking out the existing plugins, the two… May 11, 2026 at 5:07 pm
  • Editorial Team
    Editorial Team added an answer The simplest solution would probably be to grab the page… May 11, 2026 at 5:07 pm
  • Editorial Team
    Editorial Team added an answer You can make a further subclass inside your unit test… May 11, 2026 at 5:07 pm

Related Questions

I'm trying to build some code for dynamically sorting a Linq IQueryable<>. The obvious
Here's my scenario: I have a page containing several links; each link is meant
I have to interface with a slightly archaic system that doesn't use webservices. In
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.