[Matrix-SIG] Python interface for PPGPLOT

Scott M. Ransom ransom@cfa.harvard.edu
Sun, 18 Oct 1998 04:56:21 +0000


Scott M. Ransom wrote:

> PS:  I am also interested in seeing if anyone can suggest a better way
> of performing the following function (it is included in the demo code):
>
> ------------
> import Numeric
>
> def distance(width):
>     """
>     distance(width):
>         Return a 'width' x 'width' Numeric Python array with each
>             point set to the geometric distance from the array's center.
>
>     """
>     x = Numeric.arange(-width/2.0+0.5, width/2.0+0.5, 1.0)
>     x = Numeric.resize(x, (width,width))
>     return Numeric.sqrt(x**2 + Numeric.transpose(x)**2)
> ------------

Wow I'm stupid.

About 2 seconds after I sent this, I noticed that I could save a bunch of
FLOPs by simply changing the routine to read:

------------
import Numeric

def distance(width):
    """
    distance(width):
        Return a 'width' x 'width' Numeric Python array with each
            point set to the geometric distance from the array's center.

    """
    x = Numeric.arange(-width/2.0+0.5, width/2.0+0.5, 1.0)
    x = x**2
    x = Numeric.resize(x, (width,width))
    return Numeric.sqrt(x + Numeric.transpose(x))
------------

Anyone see anything else?

Scott

--
Scott M. Ransom
Phone:  (580) 536-7215             Address:  703 SW Chaucer Cir.
email:  ransom@cfa.harvard.edu               Lawton, OK  73505
PGP Fingerprint: D2 0E D0 10 CD 95 06 DA  EF 78 FE 2B CB 3A D3 53