[SciPy-dev] Numpy example for arctan2 perhaps wrong/misleading/confusing?

Anne Archibald peridot.faceted@gmail....
Tue Jun 10 03:32:44 CDT 2008


2008/6/9 David Huard <david.huard@gmail.com>:
> Samuel,
>
> What you want is this :
>
>> [4]: def arctan2(vectors):
>    ...:     """Return the angle between the x axis and each vector in
> vectors."""
>    ...:     v = np.atleast_2d(vectors)
>    ...:     return np.arctan2(v[:,0], v[:,1])
>    ...:
>
>> [5]: arctan2(([0,0], [1,0]))
> < [5]: array([ 0.        ,  1.57079633])
>
>
> You could also use the numpy.angle function which returns the angle of a
> complex argument.
>
>> [15]: np.angle([0, 1j])
>  <[15]: array([ 0.        ,  1.57079633])

Just a detail, but it would probably be better to write
np.arctan2(v[...,0], v[...,1]) (and then drop the atleast_2d). This
then works for arbitrarily-dimensioned arrays.

Anne


More information about the Scipy-dev mailing list