[SciPy-user] numarray complex comparisons

Perry Greenfield perry at stsci.edu
Wed Dec 11 20:05:45 EST 2002


> -----Original Message-----
> From: scipy-user-admin at scipy.net [mailto:scipy-user-admin at scipy.net]On
> Behalf Of eric jones
> Sent: Wednesday, December 11, 2002 6:31 PM
> To: scipy-user at scipy.net
> Subject: RE: [SciPy-user] numarray complex comparisons
 
> Hmmm. I still have a gripe though -- what if low or hi is a complex?  It
> still throws an exception.  Something like the following will solve this
> problem:
> 
>  def clip3(a,low, hi):
>  	a = asarray(a)
>  	res = where(a.real < real(low), low, a)
>  	res = where(res.real > real(hi), hi, res)
>  	return res
> 
> Explicit people should love this (I do not)!  Anyway, I'm still willing
> to go with it.  So, version 0.2 of SciPy will keep its current behavior.
> If the .real and .imag stuff are added to Numeric (which is desirable),
> we can remove complex comparison from SciPy in 0.3.  
>
But this example does raise a genericity issue along a slightly 
different line. One could argue that the function should take
arrays for low and hi also in which case all the arguments should
be wrapped with asarray(), and at least in that instance the
notation would be symmetric (a.real < low.real).

Sure, it is a bit more of a pain, but if we design functions that
are supposed to be generic, issues like this should get some thought.
Should it work with complex numbers? If so, what assumptions should
be applied to comparisons and sorting? I can see that there may be
a number of classes of functions. For some it should just plain be
an error to give them complex arguments. For others, not. I don't
think any automatic scheme will work for all intents. But we should
strive to make those that handle complex numbers as clean to write
as possible in the sense that conditional logic is not required
(but hidden in standard functions like real(), abs(), etc.)

Perry 




More information about the SciPy-User mailing list