[Numpy-discussion] Vectorizing a class method
Wed Feb 14 14:11:00 CST 2007
Anne Archibald wrote:
> The appropriate spelling for this, in modern pythons, is
> class X:
> def func(self, n):
> return 2*n
> Not that it makes it work any better.
> There's no reason vectorize couldn't be made to do the Right Thing
> when handed (bound and unbound) methods, for example by examining
> X.func.im_self, X.func.im_class and X.func.im_func attributes.
This magic is well above my current level of expertise in Python, but
perhaps one day I'll try to do it. Thanks for pointing me in this direction.
> I can't imagine a situation where a method would want to be vectorized
> over its self parameter, or at least, not by default.
Yes, I agree. I thought it would be harmless, though.
Anyway, since it seems it is not possible to vectorize() a method with
today's NumPy, I think the class' docstring, which says "[...]
somefunction -- a Python function or method" is rather misleading.
Perhaps it ought to be changed?
More information about the Numpy-discussion