[Numpy-discussion] Do ufuncs returned by frompyfunc(), have the out arg?
Ken Basye
kbasye1@jhu....
Tue Apr 6 22:48:24 CDT 2010
From: Anne Archibald <peridot.faceted@gmail.com>
On 6 April 2010 15:42, Ken Basye <kbasye1@jhu.edu> wrote:
> > Folks,
> > I hope this is a simple question. When I created a ufunc with
> > np.frompyfunc(), I got an error when I called the result with an 'out'
> > argument:
>
In fact, ordinary ufuncs do not accept names for their arguments. This
is annoying, but fixing it involves rooting around in the bowels of
the ufunc machinery, which are not hacker-friendly.
Anne
> > >>> def foo(x): return x * x + 1
> > >>> ufoo = np.frompyfunc(foo, 1, 1)
> > >>> arr = np.arange(9).reshape(3,3)
> > >>> ufoo(arr, out=arr)
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in <module>
> > TypeError: 'out' is an invalid keyword to foo (vectorized)
> >
> > But I notice that if I just put the array there as a second argument, it
> > seems to work:
> > >>> ufoo(arr, arr)
> > array([[2, 5, 26],
> > [101, 290, 677],
> > [1370, 2501, 4226]], dtype=object)
> >
> > # and now arr is the same as the return value
> >
> >
> > Is it reasonable to conclude that there is an out-arg in the resulting
> > ufunc and I just don't know the right name for it? I also tried putting
> > some other right-shaped array as a second argument and it did indeed get
> > filled in.
> >
> > Thanks as always,
> > Ken
Thanks - I hadn't noticed that it's apparently only the array methods
that can take keyword arguments. So I assume that if I call a '1-arg'
ufunc (whether from frompyfunc or an already existing one) with a second
argument, the second argument will be used as the output location.
Ken
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100406/a0a96eed/attachment.html
More information about the NumPy-Discussion
mailing list