[NumPy-Tickets] [NumPy] #1590: complex array to scalar conversion fails
Clemens Buchacher
drizzd@aon...
Fri Jan 14 15:46:18 CST 2011
On Tue, Jan 04, 2011 at 01:27:10AM -0000, NumPy Trac wrote:
>
> {{{
> complex(array([1j]))
> }}}
> fails as it does because Python first checks if the input to complex is of
> type complex, then sees if the input has a __complex__ method, and finally
> tries setting the real part to be the input converted to a float.
I think Python's complex() should be smarter. For example, if the
input is not complex and does not have a __complex__ method, but is
a sequence type, it could instead return a copy of the input with
each element converted to complex values. In general, it's probably
not useful to try and convert an array to a float.
> So, the most pressing point question is: should we put a __complex__
> method on every ndarray? If not, then what is the easiest way to add the
> __complex__ method to only the complex arrays?
I believe complex arithmetic is fundamental to numpy. So if there
is no better alternative, adding it to every ndarray seems
reasonable to me.
Cheers,
Clemens
More information about the NumPy-Tickets
mailing list