[Numpy-discussion] vectorize doesn't like functools.partial
Neal Becker
ndbecker2@gmail....
Wed Sep 8 09:53:20 CDT 2010
josef.pktd@gmail.com wrote:
> On Wed, Sep 8, 2010 at 7:44 AM, Neal Becker <ndbecker2@gmail.com> wrote:
>> If I try to use vectorize on the result of functools.partial, I seem to
>> get:
>>
>> ValueError: failed to determine the number of arguments for
>> <functools.partial object at 0x4e396d8>
>>
>> Anything I can do about it?
>
> Set .nin (attribute of vectorized function, I think) directly with
> number of arguments (int)
>
> Josef
>
>>
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
Not sure what you mean. Here is a demo of 2 problems of interop of numpy
and functools.partial. Tried both vectorize and frompyfunc. vectorize
gives:
ValueError: failed to determine the number of arguments for
<functools.partial object at 0x230b1b0>
frompyfunc gives:
TypeError: H() got multiple values for keyword argument 'iir'
Note that doc for frompyfunc says:
"Takes an arbitrary Python function..."
import numpy as np
class iir (object):
def H (z):
return 1
def H (iir, f):
z = complex (cos (2*pi*f/fs), sin (2*pi*f/fs))
return iir.H (z)
f = np.linspace (0, 10e6, 1000)
#bug1
from functools import partial
the_iir = iir()
p = partial (H, iir=the_iir)
resp_pll = np.vectorize (p)(f)
#bug2
resp_pll = np.frompyfunc (p, 1, 1)(f)
More information about the NumPy-Discussion
mailing list