[Numpy-discussion] element wise help
Thu May 7 15:22:05 CDT 2009
On Thu, May 7, 2009 at 3:39 PM, <firstname.lastname@example.org> wrote:
> On Thu, May 7, 2009 at 3:10 PM, Chris Colbert <email@example.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.
> 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.
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 *
array([ 0. , 1. , 1.41421356, 1.73205081, 2. ])
<function fun at 0x081BD0B0>
More information about the Numpy-discussion