[Numpy-discussion] arctan2 with complex args

lorenzo bolla lbolla at gmail.com
Sun Apr 29 14:50:42 EDT 2007


You make your point, but I would expect a behaviour similar to Mathematica
or Matlab.

>From http://documents.wolfram.com/mathematica/functions/ArcTan
"If x or y is complex, then ArcTan[x, y] gives . When , ArcTan[x, y] gives
the number such that and ."

Lorenzo.

On 4/29/07, David Goldsmith <David.L.Goldsmith at noaa.gov> wrote:
>
> 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)
> (0.78539816339744828+0j)
>
> DG
>
> 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 at scipy.org
> > http://projects.scipy.org/mailman/listinfo/numpy-discussion
> >
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070429/c8d9c62a/attachment.html>


More information about the NumPy-Discussion mailing list