python - Error:Index out of bounds -


as can seen, having 1000 divisions each of theta, sigma. when iterating 1 1000 theta can seen, getting error.

import time start_time = time.clock()  import numpy np theta=np.linspace(3,100,1000) sigma=np.linspace(0,10,1000) re=5  import os completename = os.path.abspath("new volume (f:)/new innings 3/sigma @ re=5 @100 .txt") file = open("sigma @ re=5 @100.txt", "w")  in np.arange(0,k,1):         //k=1000     mu=np.sqrt(re*sigma)     a=(mu-1)*np.exp(mu)+(mu+1)*np.exp(-mu)     b=2*mu*(theta[i])     c=(a/b)      d1=np.exp(mu)/(2*(mu+sigma))     d2=np.exp(-mu)/(2*(mu-sigma))     d3=mu**2     d4=np.exp(-sigma)     d5=sigma     d6=(mu**2)-(sigma**2)     d7=d3*d4     d8=d5*d6     h=d7/d8     d9=(1/sigma)     d=d1-d2+h-d9     k1=c-d     k2=np.delete(k1,0)     k3=np.nonzero(k2>0)     k4=sigma[k3]     k5=k4[0]     k55=np.array(k5)      file.write("%g\n" % k55)  file.close()  print time.clock() - start_time, "seconds" 

the output following:

 33     k3=np.nonzero(k2>0)  34     k4=sigma[k3]  35     k5=k4[0]  36     k55=np.array(k5)  indexerror: index out of bounds corresponding line 35. 

kindly help.

because k4 list becomes empty in loop, can debug ide debugger or write print statement;

import time start_time = time.clock()  import numpy np theta=np.linspace(3,100,1000) sigma=np.linspace(0,10,1000) re=5  import os completename = os.path.abspath("new volume (f:)/new innings 3/sigma @ re=5 @100 .txt") file = open("sigma @ re=5 @100.txt", "w")  in np.arange(0,1000,1):         # k=1000     mu=np.sqrt(re*sigma)     a=(mu-1)*np.exp(mu)+(mu+1)*np.exp(-mu)     b=2*mu*(theta[i])     c=(a/b)      d1=np.exp(mu)/(2*(mu+sigma))     d2=np.exp(-mu)/(2*(mu-sigma))     d3=mu**2     d4=np.exp(-sigma)     d5=sigma     d6=(mu**2)-(sigma**2)     d7=d3*d4     d8=d5*d6     h=d7/d8     d9=(1/sigma)     d=d1-d2+h-d9     k1=c-d     k2=np.delete(k1,0)     k3=np.nonzero(k2>0)     if len(k4) == 0:         print "i:",i         print "k4:",k4         break      k4=sigma[k3]     k5=k4[0]     k55=np.array(k5)      #file.write("%g\n" % k55)  file.close()  #print time.clock() - start_time, "seconds" 

it k3=np.nonzero(k2>0) statement, becomes 0 when i == 121, check algorithm again.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -