Numarray: Using sum() within functions

Jeff Epler jepler at unpythonic.net
Sun Aug 15 10:28:04 EDT 2004


On Sat, Aug 14, 2004 at 02:07:30PM -0700, Jim Cser wrote:
> Instead, I'm trying to do something like--
> def f3(x,y,z):
>    for t in range(numT):
>      tempval = f1(x,y,z,t) * f2(y,z,t)
> 
>    outval = sum(tempval,axis = 3)
>    return outval

Here, "tempval" takes on a series of values during the for loop, then
"sum" is used on value from the final iteration of the loop.

Perhaps you want something like
    def f3(x, y, z):
        temps = []
        for t in range(numT):
            temps.append(f1(...) * f(...))
        return sum(temps, axis=3)

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20040815/093f4c94/attachment.sig>


More information about the Python-list mailing list