[Numpy-discussion] real and imag functions should produce errors for object arrays
Tue Sep 21 17:35:06 CDT 2010
On Tue, Sep 21, 2010 at 3:28 PM, Robert Kern <email@example.com> wrote:
> On Tue, Sep 21, 2010 at 17:17, Pauli Virtanen <firstname.lastname@example.org> wrote:
>> Tue, 21 Sep 2010 21:50:08 +0000, Pauli Virtanen wrote:
>>> Tue, 21 Sep 2010 17:31:55 -0400, Michael Gilbert wrote:
>>>> The following example demonstrates a rather unexpected result:
>>>>>>> import numpy
>>>>>>> x = numpy.array( complex( 1.0 , 1.0 ) , numpy.object )
>>>> print x.real
>>>>>>> print x.imag
>>>> Shouldn't real and imag return an error in such a situation?
>>> It probably shouldn't do *that* at the least.
>> *that* == return a complex number from .real
> What is the alternative? I'm personally happy with saying that many of
> the operations we define on numpy arrays can be done because we know
> the types and that object arrays subvert this. numpy can't, without
> excessive amounts of magic, always know a sensible thing to do with
> object arrays, so we implement the fast thing to do.
I agree that special-casing object array .real to detect complex
contents seems a bit messy, but it does make sense I think to raise an
error from .real and .imag for non-numerical types.
More information about the NumPy-Discussion