[Numpy-discussion] Do ufuncs returned by frompyfunc() have the out arg?

Anne Archibald peridot.faceted at gmail.com
Tue Apr 6 17:52:55 EDT 2010


On 6 April 2010 15:42, Ken Basye <kbasye1 at 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
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list