Friday, 15 February 2013

Can I avoid many spaces in multiple nested loops in python? -



Can I avoid many spaces in multiple nested loops in python? -

i trying numerical calculations python. involves 7 nested loops (i have 5-dimensional array , need loop on that).

that lot of spaces or indents. spending time moving editor window left right , back, or typing in tabs/spaces.

is there way avoid this?

edit: here fortran pseudocode simplified version of problem. should show how need customize accessing 5-dimensional array fe's indices. note how operations depend on other arrays defined @ different index positions , how there conditional statements command of indices too:

do iy=1,ny ix=1,nx im=0,mmax imm=im-1 imp=im+1 nqi=ni if(im.eq.0) nqi=1 ii=1,nqi iq=3-2*ii iiz=3-ii in=im,nmax ip=1,np fb(ii,ip,in,im)=0.5d0*( fe(ii,ix,iy,ip-1,in,im)+fe(ii,ix,iy,ip+1,in,im) ) enddo fb(ii,0,in,im)=0.d0 enddo fb(ii,0,0,im)=fe(ii,ix,iy,1,0,im) ip=0,np in=im,nmax qdp=0.5*fy(ix+2,iy,ip) inm=max(0,in-1) inp=in+1 qfb=fb(ii,ip,in,im) qfb=qfb-qdp*( gb(ii,ip,inm,imm)*cgyzm(in,im) - gb(ii,ip,inm,imp)*cgyzp(in,im) ) fb(ii,ip,in,im)=qfb enddo enddo enddo ii=1 enddo enddo enddo

you should move of inner loops own functions, cut down indentation , create code easier understand well.

python

No comments:

Post a Comment