[SciPy-dev] Numpy example for arctan2 perhaps wrong/misleading/confusing?
Anne Archibald
peridot.faceted at gmail.com
Tue Jun 10 04:32:44 EDT 2008
2008/6/9 David Huard <david.huard at 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