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

Ryan May rmay31 at gmail.com
Wed Mar 25 19:22:53 EDT 2009


On Wed, Mar 25, 2009 at 3:56 PM, David Baddeley <david_baddeley at yahoo.com.au
> wrote:

>
> There's always:
>
> X, Y = numpy.mgrid[-128:128, -128:128]
> R2 = X**2 + Y**2
> p = numpy.exp(-0.01*R2)
>
> which uses a bit more memory, but avoids loops.
>
> David
>

If you use ogrid instead of mgrid, you'll avoid the increase in memory,
since the arrays are created in a form ready for broadcasting.

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20090325/a34123f0/attachment.html>


More information about the SciPy-User mailing list