From: Rob H. <he...@ta...> - 2006-05-30 17:54:05
|
Yes, brilliant. The answer is yes, but you need to modify the array to have it make sense; you need to fold the array over, so that the 'negative' indices reference data from the rear of the array.... I was thinking about having the first negative index first... I'm still not sure if this will be 'skating on dull blades with sharp knives' in converting fortran to numpy. More generally to the problem of code conversion, I think that a direct fortran -> numpy translation is not the best thing -- the numpy code should be vectorized. The array indexing problems will (mostly) go away when the fortran code is vectorized, and will result in much faster python code in the end as well. -r On May 30, 2006, at 12:42 PM, Alan Isaac wrote: >> On May 30, 2006, at 11:28 AM, Rick Muller wrote: >>> Is it possible to create arrays that run from, say -5:5, rather >>> than 0:11? Analogous to the Fortran "allocate(A(-5:5))" command? >>> I'm translating a F90 code to Python, and it would be easier to do >>> this than to use a python dictionary. > > > On Tue, 30 May 2006, Rob Hetland wrote: >> I believe Rick is talking about negative indices (possible in >> FORTRAN), in which case the answer is no. > > > > I see. > Perhaps this is still relevant? > (Or perhaps not.) > >>>> y=N.arange(11) >>>> x=range(-5,6) >>>> y[x] > array([ 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5]) >>>> > > hth, > Alan Isaac > > > > > > > ------------------------------------------------------- > All the advantages of Linux Managed Hosting--Without the Cost and > Risk! > Fully trained technicians. The highest number of Red Hat > certifications in > the hosting industry. Fanatical Support. Click to learn more > http://sel.as-us.falkag.net/sel? > cmd=lnk&kid=107521&bid=248729&dat=121642 > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion ----- Rob Hetland, Assistant Professor Dept of Oceanography, Texas A&M University p: 979-458-0096, f: 979-845-6331 e: he...@ta..., w: http://pong.tamu.edu |