[Numpy-discussion] Array of Callables

Anne Archibald peridot.faceted@gmail....
Wed Mar 21 13:32:21 CDT 2007


On 21/03/07, Andrew Corrigan <acorriga@gmu.edu> wrote:
> Thanks for pointing that out.  Technically that works, but it doesn't really
> express this operation as concisely and as naturally as I'd like to be able to.
>
> What I really want is to be able to write:
>
> >>> a = array([lambda x: x**2, lambda x: x**3])
> >>> b = arange(5)
> >>> a(b)
>
> and get:
> array([[ 0,  1,  4,  9, 16],
>        [ 0,  1,  8, 27, 64]])

Well, this only makes sense for an array of callables. So you could
hope for a "callable" dtype to be put into numpy, or you could write
your own array class, derived from the standard one, that only holds
callables and that implements a __call__ method.

Anne


More information about the Numpy-discussion mailing list