[SciPy-dev] Numpy example for arctan2 perhaps wrong/misleading/confusing?
David Huard
david.huard@gmail....
Tue Jun 10 07:42:23 CDT 2008
2008/6/10 Anne Archibald <peridot.faceted@gmail.com>:
> 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.
>
Nice.
Thanks for the pointer,
David
>
> Anne
> _______________________________________________
> Scipy-dev mailing list
> Scipy-dev@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-dev/attachments/20080610/9a93abb2/attachment.html
More information about the Scipy-dev
mailing list