1
c = file('cluster_info.txt')
for i in zip(ys[-10:],result): # has ten elements
    for j in c.readlines():
        cluster = j.split(',')
        if q in cluster:
            m = (q[i],cluster[0])
            f = pylab.figure() # code for plot starts here
            for n, fname in enumerate(m):
                image=Image.open(fname).convert("L")
                arr=np.asarray(image)
                f.add_subplot(2, 1, n)  # this line outputs images on top of each other
                pylab.imshow(arr,cmap=cm.Greys_r)
            pylab.title("%s, Top:Predicted,Bottom:Observed" %i[0])
            pylab.show()
        else:
            continue

This is a snippet from a larger code, and I expect to produce 10 images/plots but no plots are produced by python. I think I am not nesting the if and else: correctly in the for loop. Please tell me what is wrong here.

1
  • 7
    Where is do-my-work-for-me tag? Commented May 4, 2012 at 11:21

1 Answer 1

2

what is your intention of else: continue? if you want to continue with the outer loop (i), you'd better use else:break. otherwise you may just as well delete the else branch

also, i does not seem to be used in your loop at all? it can't be right

Sign up to request clarification or add additional context in comments.

3 Comments

I need to continue through the loop in j and then continue through loop in i
should there be two else: at the end?
this question is very hard to answer (and actually a good candiate to down-vote). if seems that q in cluster was never true. try to find out why this is the case (what are the values of q and cluster in each iteration). also, check the value of m to see if the n, fname loop is ever executed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.