logo       

Re: Using sum() within a function: msg#00042

python.numeric.general

Subject: Re: Using sum() within a function

Perry Greenfield wrote:

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


The loop was indeed wrong, and "tempval = 0.*x" was the trick I needed, thanks. Unfortunately, iterating over t is still extremely slow. Ideally, there would be a way to use fromfunction() with slices as arguments.

-Jim


-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise