Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Backward loop in Python

I need to loop backwards from i=n-2 to i = 0 to code this math formula:

math formula

for i in range(n-2,0):
    X[i] = Y[i]
    for m in range(i+1,n):

        X[i] = X[i] - T[i,m] * X[m]

It doesn’t work, what am I doing wrong?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

All numbers from numpy arrays

>Solution :

if you want to loop backward you can use the for loop like following

range(start, end, step)

the step is 1 by default. in your case, you have to specify the decrement in order the loop the work.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading