How can I write Q array to excel after the loop ends? Or How can I see the data that is stored in Q after the loop ends?
Nlayers=23
N=365
def main_loop(Z,z,Areat0,Areat1,TempLake,i,HSR,TD,FW,wind):
Q=np.zeros(len(rad))
Q[0]=0
Q[i+1]=Qn(HSR,TD,FW,TempLake[0])
Q0=Q[i]
Q1=Q[i+1]
n=TempLake.size
var00=Imp_scheme(Q0,Q1,z,Areat0,Areat1,Z,TempLake,wind)
var01=fix_profile(n,var00,Areat0)
return var01
TempLake=np.zeros((N,Nlayers))
TempLake[0]=T0
for i in xrange(N-1):
TempLake[i+1]=main_loop(Z,z,Areat0,Areat1,TempLake[i],i,HSR[i],TD[i],FW[i],wind[i])
The short answer is that you can’t without a) returning it, b) passing it in and modifying it, or c) declaring it as a global or something equivalent. In most cases
ais the best. In the last line of the function, you could do this:And in the main
forloop:But this is a rather awkward design in your case, since you’re returning
QNtimes, but only using it once. Probably there’s a better approach, but I can’t tell from your example code what you’re really doing, so I can’t figure out what it might be.