[Numpy-discussion] element wise help

Chris Colbert sccolbert@gmail....
Thu May 7 12:41:31 CDT 2009


its part of a larger program for designing PID controllers. This particular
function numerical calculates the inverse laplace transform using riemann
sums.

The exec statements, from what i gather, allow the follow eval statement to
be executed in the scope of numpy and its functions. I don't get how it
works either, but it doesnt work without it.

I've just about got something working using broadcasting and will post it
soon.

chris

On Thu, May 7, 2009 at 1:37 PM, <josef.pktd@gmail.com> wrote:

> On Thu, May 7, 2009 at 1:08 PM, Chris Colbert <sccolbert@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
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090507/7603d9ed/attachment.html 


More information about the Numpy-discussion mailing list