[英]How to append a empty list within for loop in Python
a=np.where(MACD[2]>0.)[0]
b=np.where(MACD[2]<0.)[0]
num=np.array([1,2])
num1=[]
for x in range (-1,-30,-1):
while True:
if(a[x]-a[x-1]>1):
num1.append(num)
print num1
break
I want to append num but when I run it is hang over there. 我想附加num,但是当我运行时它挂在那边。 My desired output is num=[45,74,41,1,2] which mean the num1 will not be overwrite everytime it run while the for loop.
我想要的输出是num = [45,74,41,1,2],这意味着num1每次在for循环中运行时都不会被覆盖。
a=np.where(MACD[2]>0.)[0]
b=np.where(MACD[2]<0.)[0]
num=np.array([1])
num1=[]
for x in range (-1,-30,-1):#for MACD above 0
if(a[x]-a[x-1]>1):
num=a[x]
num1.append(num)
print num1
found out that additional num=a[x] will do 发现额外的num = a [x]将起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.