[Numpy-discussion] Re: Using sum() within a function
Jim Cser
jimcser at pacifier.com
Tue Aug 17 13:54:01 EDT 2004
> Example-- variables x,y,z,t; dimensions numX, numY, numZ, numT;
> functions f1(x,y,z,t), f2(y,z,t); want to calculate f1*f2 and
> sum over t to get out[x,y,z].
Cobbling together a number of suggestions, what finally worked was--
def f3(x, y, z, t_range=arange(numT)):
tempval = 0.* x
for t in t_range:
tempval += f1(x,y,z,t) + f2(y,z,t)
return tempval
out = fromfunction(f3,(numX,numY,numZ,1))
I couldn't quite get sum() to work inside the function, but this
is definitely good enough for now. Thanks to all for your help.
-Jim Cser
More information about the NumPy-Discussion
mailing list