[Numpy-discussion] complex comparisons

Fernando Perez Fernando.Perez at colorado.edu
Mon Mar 20 10:15:27 CST 2006


Travis Oliphant wrote:
> Tim Hochberg wrote:
> 
>>I just noticed that complex arrays can be compared using [<, <=, > and 
>>
>>>=]. Do we really want  this? I'd prefer to follow numarray's lead 
>>
>>here and only support [==, !=] on complex arrays.
>>
> 
> MATLAB has always provided complex comparisons by comparing the real 
> part, so there is signifcant precedence for this. 
> 
> Anybody coming from MATLAB will appreciate it because while technically 
> complex numbers are not ordered, often complex arrays are the result of 
> calculations that result in real numbers but the data-type is still 
> complex. 
> 
> But, now that .real and .imag work on *all* array data-types it is not 
> an absolute necessity to support complex comparisons.  I just think it's 
> convenient and not especially confusing.

Well, I think this is one of those cases where we should strive more for 
uniformity with /Python/ than with matlab:

In [18]: 1j<2j
---------------------------------------------------------------------------
exceptions.TypeError                                 Traceback (most recent 
call last)

/home/fperez/<ipython console>

TypeError: cannot compare complex numbers using <, <=, >, >=

Just my 1e-2j :)

f




More information about the Numpy-discussion mailing list