[Numpy-discussion] real and imag functions should produce errors for object arrays
Benjamin Root
ben.root at ou.edu
Tue Sep 21 18:23:08 EDT 2010
On Tue, Sep 21, 2010 at 4:44 PM, Benjamin Root <ben.root at ou.edu> wrote:
> On Tue, Sep 21, 2010 at 4:31 PM, Michael Gilbert <
> michael.s.gilbert at gmail.com> wrote:
>
>> Hi,
>>
>> The following example demonstrates a rather unexpected result:
>>
>> >>> import numpy
>> >>> x = numpy.array( complex( 1.0 , 1.0 ) , numpy.object )
>> >>> print x.real
>> (1+1j)
>> >>> print x.imag
>> 0
>>
>> Shouldn't real and imag return an error in such a situation?
>>
>> Thanks,
>> Mike
>>
>
> Don't use 'numpy.object'. Because complex is a numerical type, numpy can
> handle it just fine. By setting dtype to numpy.object, numpy then treats it
> like an object rather than a numerical.
>
> x = numpy.array( complex(1.0, 1.0) )
>
> should work just fine.
>
> I hope that helps!
> Ben Root
>
>
I see that I have interpreted this thread as "Doctor, it hurts when I do
this... Well, don't do that!" Sorry for the noise.
Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100921/01bc5b65/attachment.html>
More information about the NumPy-Discussion
mailing list