[Numpy-discussion] Vectorizing a function

YW yichun.wei@gmail....
Wed Jan 30 03:18:39 CST 2008


Try use a closure.

On Jan 30, 12:49 am, LB <berthe.l...@gmail.com> wrote:
>    Hi,
>
> I've got some questions on the numpy.vectorize  function.
> Currently, i'm doing this kind of work :
>
> [ code]
> def calc_0d(x, y):
>     """ make complexe calculation using two scalars x and y """
>     [ ... ]
>     return res1, res2, res 3
>
> # vectorize the function
> calc = vectorize(calc_0d)
>
> res1, res_2, res_3 = calc(array_x, array_y)
> [/code]
>
> This works fine. Really impressive. Good work for this !
>
> My problem is that the complexe calculations made in calc_0d use some
> parameters, which are currently defined at the head of my python file.
> This is not very nice and I can't define a module containing theses
> two functions and call them with different parameters.
>
> I would like to make this cleaner and pass theses parameter as
> keyword  argument, but this don't seems to be possible with vectorize.
> Indeed, some of theses parameters are array parameters and only the x
> and y arguments should be interpreted with the broadcasting rules....
>
> What is the "good way" for doing this ?
>
> Regards,
>
> --
> LB
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discuss...@scipy.orghttp://projects.scipy.org/mailman/listinfo/numpy-discussion


More information about the Numpy-discussion mailing list