[Numpy-discussion] element wise help
josef.pktd at gmail.com
josef.pktd at gmail.com
Thu May 7 13:37:40 EDT 2009
On Thu, May 7, 2009 at 1:08 PM, Chris Colbert <sccolbert at gmail.com> wrote:
> let me just post my code:
>
> t is the time array and n is also an array.
>
> For every value of time t, these operations are performed on the entire
> array n. Then, n is summed to a scalar which represents the system response
> at time t.
>
> I would like to eliminate this for loop if possible.
>
> Chris
>
> #### code ####
>
> b = 4.7
> f = []
> n = arange(1, N+1, 1)
>
> for t in timearray:
> arg1 = {'S': ((b/t) + (1J*n*pi/t))}
> exec('from numpy import *', arg1)
> tempval = eval(transform, arg1)*((-1)**n)
> rsum = tempval.real.sum()
> arg2 = {'S': b/t}
> exec('from numpy import *', arg2)
> tempval2 = eval(transform, arg2)*0.5
> fval = (exp(b) / t) * (tempval2 + rsum)
> f.append(fval)
>
>
> #### /code #####
>
I don't understand what the exec statements are doing, I never use it.
what is transform?
Can you use regular functions instead or is there a special reason for
the exec and eval?
In these expressions ((b/t) + (1J*n*pi/t)), (exp(b) / t)
broadcasting can be used.
Whats the size of t and n?
Josef
More information about the NumPy-Discussion
mailing list