Numeric array and for loops problem

Chad Netzer cnetzer at
Wed Jan 8 01:11:58 CET 2003

On Tuesday 07 January 2003 05:29, Stan wrote:

>  worldarray[x,y] = val
>  x += 1
>  y += 1/2
> Doesn't work..

As others pointed out, 1/2 (currently) in python evaluates to 0 (integer 
division truncation of the remainder).

However, if you wanted to increment y by a half, ie:

y += 0.5

then you'll find that you can't index into the array with a floating point 
value.  That is because indices are whole numbers, representing the order of 
items, they are not a continuum.

You need to allocate your grid to the finest precision you will need, then 
scale your indices appropriately.  If you need both a HUGE grid, and a very 
fine grid, you will run out of memory, and need to use techniques where you 
are only operating on small subsets of the entire conceptual grid at any one 

Good luck with your project; it may be ambitious for a beginning programmer, 
but you will learn a lot I expect.

Bay Area Python Interest Group -

Chad Netzer
cnetzer at

More information about the Python-list mailing list