arrays - Porting IDL code, lindgen function to Python -


afternoon everyone. i'm porting on idl code python , it's been plain sailing until point far. i'm stuck on section of idl code:

nsteps = 266     ind2 = ((lindgen(nsteps+1,nsteps+1)) mod (nsteps+1)) dk2 = (k2arr((ind2+1) < nsteps) - k2arr(ind2-1) > 0)) / 2. 

my version of includes rewritten lindgen function follows:

def pylindgen(shape):     nelem = numpy.prod(numpy.array(shape))     out = numpy.arange(nelem,dtype=int)     return numpy.reshape(out,shape) 

... , ported code k2arr array of shape (267,):

ind2 = pylindgen((nsteps+1,nsteps+1)) % (nsteps+1) dk2 = (k2arr[ (ind2+1) < nsteps ] - k2arr[ (ind2-1) > 0. ]) / 2. 

now, problem code makes ind2 array where, looking @ idl code , errors thrown in python script, i'm sure it's meant scalar. missing feature of these idl functions?

any thoughts appreciated. cheers.

my knowledge of idl not used be, had research little. operator ">" in idl not equivalent of python (or other languages). stablishes maximum, above set value. same goes "<", obviously, sets minimum.

dk2 = (k2arr((ind2+1) < nsteps) - k2arr(ind2-1) > 0)) k2arr 266 , ind2 (266,266) equivalent saying:

 - (ind2+1 < nsteps) take ind2+1 and, in place ind2+1     greater nsteps, replace nsteps.   - (ind2-1 > 0) take ind2-1 and, in place ind2-1     less zero, put 0 instead.  

the tricky part now. k2arr (266,) evaluated each of rows of (ind2+1) , (ind2-1), meaning if (ind2+1 < nsteps) = [1,2,3,...,nsteps-1, nsteps, nsteps] k2arr evaluated 266 times, 1 on top of other, result being (266,266) array.

and remember why stopped programming in idl!


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -