[Numpy-discussion] Strange error taking log of PyObject array

Tim Hochberg tim.hochberg at cox.net
Mon Jul 10 23:35:35 CDT 2006

Travis Oliphant wrote:
> Tom Denniston wrote:
>> The following works on a float array but not an object array.  It
>> gives a very strange error message.
>> (Pdb) numpy.log(numpy.array([19155613843.7], dtype=object))
>> *** AttributeError: 'float' object has no attribute 'log'
> This is expected behavior.  For object arrays the ufuncs look to the 
> objects themselves for implementation.   In this case.  The ufunc tries 
> to call the log method of each entry in the array.  The first entry is a 
> float (which as the error shows) does not have a log attribute and so 
> you get a failure.
It seems like we could do better than this. Couldn't the ufunc call 
*itself* on on objects in an object array? That is, ufunc(object_array) 
would be more or less equivalent to map(ufunc, object_array)  [mostly 
less, but hopefully you get the idea]. I haven't looked into the gory 
details, and I'm not likely to soon since I'm tied up with other stuff, 
but I figured I'd toss the idea into the ring.


More information about the Numpy-discussion mailing list