reduce function of vectorize doesn't respect dtype?
def a(x,y): return x+y b = vectorize(a) c = array([1,2]) b(c, c) # use once to populate b.ufunc d = b.ufunc.reduce(c) c.dtype, type(d)
The reduce function of ufunc of a vectorized function doesn't seem to respect the dtype. dtype('int32'), <type 'int'>
c = array([[1,2,3],[4,5,6]]) b.ufunc.reduce(c) array([5, 7, 9], dtype=object)
My goal is to use the output of vectorize() as if it is actually a ufunc. So I'd really like to just type: b.reduce, b.accumulate, etc. And I don't want to have to write (after using it once to populate b.ufunc): b.ufunc.reduce(c).astype(numpy.int32)
On Fri, Aug 7, 2009 at 11:54 AM, T J<tjhnson@gmail.com> wrote:
The reduce function of ufunc of a vectorized function doesn't seem to respect the dtype.
def a(x,y): return x+y b = vectorize(a) c = array([1,2]) b(c, c) # use once to populate b.ufunc d = b.ufunc.reduce(c) c.dtype, type(d) dtype('int32'), <type 'int'>
c = array([[1,2,3],[4,5,6]]) b.ufunc.reduce(c) array([5, 7, 9], dtype=object)
d = b.ufunc.reduce(c) type(d[0]) <type 'int'> d.dtype
So is this a bug? Or am I doing something wrong? In the second example.... dtype('object')
On Fri, Aug 7, 2009 at 13:54, T J<tjhnson@gmail.com> wrote:
The reduce function of ufunc of a vectorized function doesn't seem to respect the dtype.
def a(x,y): return x+y b = vectorize(a) c = array([1,2]) b(c, c) # use once to populate b.ufunc d = b.ufunc.reduce(c) c.dtype, type(d) dtype('int32'), <type 'int'>
c = array([[1,2,3],[4,5,6]]) b.ufunc.reduce(c) array([5, 7, 9], dtype=object)
My goal is to use the output of vectorize() as if it is actually a ufunc.
vectorize()d ufuncs are always object->object ufuncs because Python functions take objects and return objects, not C ints or other C data types. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
participants (2)
-
Robert Kern
-
T J