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

Ken Basye kbasye1 at jhu.edu
Tue Apr 6 15:42:41 EDT 2010


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:

 >>> 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




More information about the NumPy-Discussion mailing list