[SciPy-user] Python loops too slow

Ross Williamson Ross.Williamson at usap.gov
Wed Apr 8 23:26:56 EDT 2009


Thanks Robert

Apologies for not searching the mailing list but I'm working over 
Iridium and only have email - no WWW :(

bincount worked a treat

Ross
> On Wed, Apr 8, 2009 at 22:02, Ross Williamson <Ross.Williamson at usap.gov> wrote:
>   
>> Ok so this is really annoying and slowing my code down.
>>
>> I've tried:
>>
>> nsamp = zeros(711)
>> mask = ones(1000*1000)
>> binned_all is (1000*1000 set of indices including numbers between 0 and 710)
>>
>> rbl = binned_ell.ravel()
>> rmask = mask.ravel()
>>
>> nsamp[rbl] = nsamp[rbl] + mask
>>
>> And all it does is just add 1 to each element of nsamp - i.e. nsamp is
>> now all ones rather than zeros and not the cumulative sum of the number
>> of elements in binned_all (Note I'm using one here to make life easy -
>> in reality it will be  a float of different values)
>>     
>
> The reason why this can't work has been explained many times on this
> list. The right way to do this is to use bincount().
>
>   



More information about the SciPy-User mailing list