[SciPy-user] Python loops too slow

Pauli Virtanen pav@iki...
Wed Apr 8 08:14:07 CDT 2009


Wed, 08 Apr 2009 23:12:03 +1200, Ross Williamson kirjoitti:
[clip]
>    result = zeros([ngrid, ngrid])
> 
>    for i in arange((ngrid / 2)+1):
>       for j in arange((ngrid / 2)+1):
>          result[j,i] = 2. * pi * sqrt(i ** 2. + j ** 2) / reso /
>          (ngrid*1.0)

i = arange(ngrid/2 + 1)
j = arange(ngrid/2 + 1)
result = 2*pi*hypot(i[None,:], j[:,None])/reso/ngrid

-- 
Pauli Virtanen



More information about the SciPy-user mailing list