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

David Vine djvine at gmail.com
Wed Mar 25 10:58:11 EDT 2009


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/20090325/4d06a950/attachment.html>


More information about the SciPy-User mailing list