[Numpy-discussion] element wise help
Chris Colbert
sccolbert@gmail....
Thu May 7 15:25:19 CDT 2009
that's essentially what the eval statement does.
On Thu, May 7, 2009 at 4:22 PM, <josef.pktd@gmail.com> wrote:
> On Thu, May 7, 2009 at 3:39 PM, <josef.pktd@gmail.com> wrote:
> > On Thu, May 7, 2009 at 3:10 PM, Chris Colbert <sccolbert@gmail.com>
> wrote:
> >> the user of the program inputs the transform in a text field. So I have
> no
> >> way of know the function apriori.
> >>
> >> that doesn't mean I still couldn't throw the exec and eval commands into
> >> another function just to clean things up.
> >>
> >> Chris
> >
> > No, I think this is ok then, it is similar to what sympy.lambdify
> > does. Now you call exec only twice, which might have been the main
> > slowdown in the loop version.
> >
> > In this case, users need to write vectorized transform functions that
> > handle the full n x t array.
> >
> > Josef
>
> this would be an alternative, which might also work better in a loop,
> requires numpy.* in local scope
>
> >>> transform = 'sqrt(x)'
> >>> exec('def fun(x): return ' + transform)
> >>> from numpy import *
> >>> fun(5)
> 2.2360679774997898
> >>> fun(np.arange(5))
> array([ 0. , 1. , 1.41421356, 1.73205081, 2. ])
> >>>
> >>> fun
> <function fun at 0x081BD0B0>
>
> 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/7f979ca7/attachment.html
More information about the Numpy-discussion
mailing list