我的代码中有五个循环,我想在我设置的时间停止每个循环。我的代码是:
nw=1000
for i in range(nw):
w_list.append(-3+0.006*i)
chi_1=0
chi_2=0
k=1
while k<10:
now_1=time.time()
l=1
while l<10:
now_2=time.time()
n_1=0
while n_1<10:
now_3=time.time()
n_2=0
while n_2<5:
now_4=time.time()
chi_2+=(e1_vecs[n_1,0]*e1_vecs[n_1,k]*e_vecs[2*n_2,0]*e_vecs[2*n_2,l])**2*(1.0/(w_list[i]+(E0-e_vals[l]-k*w_b+b*w_b)-0.001j))+(e1_vecs[n_1,0]*e1_vecs[n_1,k]*e_vecs[2*n_2+1,0]*e_vecs[2*n_2+1,l])**2*(1.0/(w_list[i]-(E0-e_vals[l]-k*w_b+b*w_b)+0.001j))
n_2+=1
stop_4=time.time()-now_4
time.sleep(1.0-stop_4)
n_1+=1
stop_3=time.time()-now_3
time.sleep(1.0-stop_3)
l+=1
stop_2=time.time()-now_2
time.sleep(1.0-stop_2)
k+=1
stop_1=time.time()-now_1
time.sleep(1.0-stop_2)
chi_on.append(chi_2.imag)
但是我的方法不行……你有什么好的建议吗?我是编程初学者...