[Numpy-discussion] Upgrade to 1.6.x: frompyfunc() ufunc casting issue
Fri Jan 20 15:55:43 CST 2012
A long time ago, Aditya Sethi <ady.sethi@gmail... wrote:
> I am facing an issue upgrading numpy from 1.5.1 to 1.6.1.
> In numPy 1.6, the casting behaviour for ufunc has changed and has become
> Can someone advise how to implement the below simple example which worked in
> 1.5.1 but fails in 1.6.1?
> >>> import numpy as np
> >>> def add(a,b):
> ... return (a+b)
> >>> uadd = np.frompyfunc(add,2,1)
> >>> uadd
> <ufunc 'add (vectorized)'>
> >>> uadd.accumulate([1,2,3])
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ValueError: could not find a matching type for add (vectorized).accumulate,
> requested type has type code 'l'
Here's the workaround I found to that problem:
>>> uadd.accumulate([1,2,3], dtype='object')
array([1, 3, 6], dtype=object)
It seems like "accumulate" infers that 'l' is the required output dtype,
but does not have the appropriate implementation:
Forcing the output dtype to be 'object' (the only supported dtype) seems
to do the trick.
Hope this helps,
More information about the NumPy-Discussion