Re: looping in array vs looping in a dic

2012-09-20 Thread MRAB
On 2012-09-21 00:35, giuseppe.amatu...@gmail.com wrote: Hi Ian and MRAB thanks to you input i have improve the speed of my code. Definitely reading in dic() is faster. I have one more question. In the dic() I calculate the sum of the values, but i want count also the number of observation, in

Re: looping in array vs looping in a dic

2012-09-20 Thread giuseppe . amatulli
Hi Ian and MRAB thanks to you input i have improve the speed of my code. Definitely reading in dic() is faster. I have one more question. In the dic() I calculate the sum of the values, but i want count also the number of observation, in order to calculate the average in the end. Should i creat

Re: looping in array vs looping in a dic

2012-09-20 Thread Ian Kelly
On Thu, Sep 20, 2012 at 1:28 PM, Ian Kelly wrote: > Expanding on what MRAB wrote, since you probably have far fewer > categories than pixels, you may be able to take better advantage of > numpy's vectorized operations (which are pretty much the whole point > of using numpy in the first place) by l

Re: looping in array vs looping in a dic

2012-09-20 Thread Ian Kelly
On Thu, Sep 20, 2012 at 1:09 PM, MRAB wrote: > for col in range(cols): > for row in range(rows): > cat = valuesCategory[row, col] > ras = valuesRaster[row, col] > totals[cat] += ras Expanding on what MRAB wrote, since you probably have far fewer categories than pixels,

Re: looping in array vs looping in a dic

2012-09-20 Thread MRAB
On 2012-09-20 19:31, giuseppe.amatu...@gmail.com wrote: Hi, I have this script in python that i need to apply for very large arrays (arrays coming from satellite images). The script works grate but i would like to speed up the process. The larger computational time is in the for loop process. Is

looping in array vs looping in a dic

2012-09-20 Thread giuseppe . amatulli
Hi, I have this script in python that i need to apply for very large arrays (arrays coming from satellite images). The script works grate but i would like to speed up the process. The larger computational time is in the for loop process. Is there is a way to improve that part? Should be better