[Numpy-discussion] real and imag functions should produce errors for object arrays
Benjamin Root
ben.root at ou.edu
Tue Sep 21 17:44:21 EDT 2010
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100921/930e7062/attachment.html>
More information about the NumPy-Discussion
mailing list