[Numpy-discussion] Using sum() within a function
Perry Greenfield
perry at stsci.edu
Sat Aug 14 14:44:32 CDT 2004
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
>
Perhaps I'm confused but it seems to me the for loop is wrong.
Don't you want something like:
def f3(x,y,z):
tempval = 0.*x
for t in range(numT):
tempval += f1(x,y,z,t) * f2(y,z,t)
return tempval
Instead?
Not that I've tried this, but so long as the function will
work given 3-d arrays for x,y,z, it should. (though the dependence
on numT as a global is a bit worrisome)
Perry GReenfield
More information about the Numpy-discussion
mailing list