[Numpy-discussion] complex comparisons

Tim Hochberg tim.hochberg at cox.net
Mon Mar 20 10:24:02 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.


FWIW, it confused me. My first guess was that it was a bug. My second 
guess that it was comparing complex numbers by their magnitude. It was 
only after I dug into the code that I realized that it was comparing 
real, then imaginary. (I suppose I could have tried to look in the docs 
too, but it somehow seemed easier just to look in umathmodule).

Although I use complex numbers all the time,  I'm not going to use this, 
so in my case it's just a chance for errors to sneak into my code that 
would otherwise be caught.

Much as I love MATLAB people, heck some of my best friends are MATLAB 
people, I don't think this is a place we should be catering to them.

My $0.02.

-tim





More information about the Numpy-discussion mailing list