Re: [Numpy-discussion] Do ufuncs returned by frompyfunc(), have the out arg?
From: Anne Archibald On 6 April 2010 15:42, Ken Basye 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 "", line 1, in > 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 ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Do ufuncs returned by frompyfunc() have the out arg?
On 6 April 2010 15:42, Ken Basye 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 "", line 1, in > 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@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Do ufuncs returned by frompyfunc() have the out arg?
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 "", line 1, in 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@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion