2012-05-04 89 views
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 

这是一个较大代码的代码片段,我期望生成10个图像/图,但python不生成图。我认为我不是在for循环中正确嵌套if和else:。请告诉我这里有什么问题。if语句嵌套在for循环中

+7

do-my-work-for-me标签在哪里? – Begemoth

回答

2

你的意图是什么else: continue?如果要继续使用外部循环(i),最好使用else:break。否则你也可以删除else分支

也,i似乎并没有在你的循环中使用?它不可能是正确的

+0

我需要继续通过j中的循环,然后继续通过循环在我 – balibakbar

+0

是的,对不起,我在那里作为“q [我]” – balibakbar

+0

应该有两个:在最后? – balibakbar