[Numpy-discussion] element wise help
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, <firstname.lastname@example.org> wrote:
> On Thu, May 7, 2009 at 3:39 PM, <email@example.com> wrote:
> > On Thu, May 7, 2009 at 3:10 PM, Chris Colbert <firstname.lastname@example.org>
> >> the user of the program inputs the transform in a text field. So I have
> >> 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)
> >>> fun(np.arange(5))
> array([ 0. , 1. , 1.41421356, 1.73205081, 2. ])
> >>> fun
> <function fun at 0x081BD0B0>
> Numpy-discussion mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion