[Numpy-discussion] arctan2 with complex args

David Goldsmith David.L.Goldsmith@noaa....
Sun Apr 29 12:11:41 CDT 2007

I'll take a stab at this one; if I miss the mark, people, please chime in.

What's "strange" here is not numpy's behavior but octave's (IMO).  
Remember that, over R, arctan is used in two different ways: one is 
simply as a map from (-inf, inf) -> (-pi/2,pi/2) - here, let's call that 
invtan; the other is as a means to determine "the angle" (conventionally 
taken to be between -pi and pi) of a point in the plane - but since, for 
example, tan(pi/4) = tan(-3pi/4) (and in general tan(x) = tan(x-pi)) to 
uniquely determine said angle, we need to keep track of and take into 
account the quadrant in which the point lies; this is (the only reason) 
why arctan2 is a function of two arguments, one representing the 
abscissa, the other the ordinate of the point.  But when the argument is 
complex (arctan2, as the inverse of the tangent function, *is* a valid 
function on C), this geometric use no longer makes sense, so there's 
really no reason to implement arctan2(z,w), z, w complex.  If for some 
reason, e.g., uniformity of algorithmic expression - I don't see any 
(simple) way to preserve uniformity of code expression - as near as I 
can tell, you're going to have to implement an if/else if you need to 
allow for the invtan of two complex arguments - you need to handle 
arctan2(z,w), implement it as arctan(w/z):

 >>> import numpy
 >>> numpy.arctan(1j/1j)


lorenzo bolla wrote:
> Weird behaviour with arctan2(complex,complex).
> Take  a look at this:
> In [11]: numpy.arctan2(1.,1.)
> Out[11]: 0.785398163397
> In [12]: numpy.arctan2(1j,1j)
> ---------------------------------------------------------------------------
> exceptions.AttributeError                            Traceback (most 
> recent call last)
> AttributeError: 'complex' object has no attribute 'arctan2'
> same error for:
> In [13]: numpy.arctan2(1j,1.)
> In [14]: numpy.arctan2(1.,1j)
> But arctan2 is defined for complex arguments, as far as Octave knows :-) :
> octave:7> atan2(1,1)
> ans = 0.78540
> octave:8> atan2(1j,1j)
> ans = 0
> octave:9> atan2(1j,1)
> ans = 0
> octave:10> atan2(1,1j)
> ans = 1.5708
> bug or wanted behaviour?
> Lorenzo.
> ------------------------------------------------------------------------
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion

More information about the Numpy-discussion mailing list