[SciPy-user] Loopless square 2d arrays with radially symmetricfunctions

Jean-Paul.JADAUD@C... Jean-Paul.JADAUD@C...
Tue Mar 31 08:11:19 CDT 2009


You may try something like 

import scipy as S

x = S.linspace(-128,128,256)

y = S.linspace(-128,128, 256)

mx,my =S.meshgrid(x,y)

r = S.sqrt(mx**2 +my**2)

p = S.exp(-0.01*r)

 

 

JP

________________________________

De : scipy-user-bounces@scipy.org [mailto:scipy-user-bounces@scipy.org] De la part de David Vine
Envoyé : mercredi 25 mars 2009 15:58
À : scipy-user@scipy.org
Objet : [SciPy-user] Loopless square 2d arrays with radially symmetricfunctions

 

Hello,

I use a lot of radially symmetric arrays in my code and I would like to know if there is a more efficient method for creating these arrays than the nested for-loops i am currently using.

For example, to create a Gaussian I would currently do this (Python 2.5, Ubuntu Intrepid):
import scipy
p = scipy.zeros((256,256))
for i in xrange(256):
   for j in xrange(256):
       p[i,j] = exp(-0.01*( (i-128.)**2. - (j-128.)**2.)  )

and my question is whether there is a more efficient 'loopless' method (i.e involving no for-loops) ?

Thanks in advance
David



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20090331/cf554e51/attachment.html 


More information about the SciPy-user mailing list