[Numpy-discussion] Vectorizing a function

Timothy Hochberg tim.hochberg@ieee....
Wed Jan 30 11:18:09 CST 2008


On Jan 30, 2008 10:10 AM, Charles R Harris <charlesr.harris@gmail.com>
wrote:

[SNIP]


>
> IIRC, the way to do closures in Python is something like
>
> In [5]: def factory(x) :
>    ...:     def f() :
>    ...:         print x
>    ...:     f.x = x
>    ...:     return f
>    ...:
>
> In [6]: f = factory("Hello world.")
>
> In [7]: f()
> Hello world.
>
> There is a reason to do it that way, but I don't recall what it is.
>

You don't need the "f.x = x" line. It's possible it has some beneficial side
effect that I don't recall, but basic closures work fine without out.

Nor do I know if the result can be vectorized, I've never used vectorize.
>

I expect they could be, but I don't use vectorize either.


-- 
.  __
.   |-\
.
.  tim.hochberg@ieee.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080130/f062bcea/attachment.html 


More information about the Numpy-discussion mailing list