[SciPy-dev] Numpy example for arctan2 perhaps wrong/misleading/confusing?
Mon Jun 9 10:33:04 CDT 2008
What you want is this :
> : def arctan2(vectors):
...: """Return the angle between the x axis and each vector in
...: v = np.atleast_2d(vectors)
...: return np.arctan2(v[:,0], v[:,1])
> : arctan2(([0,0], [1,0]))
< : array([ 0. , 1.57079633])
You could also use the numpy.angle function which returns the angle of a
> : np.angle([0, 1j])
<: array([ 0. , 1.57079633])
2008/6/9 Samuel John <firstname.lastname@example.org>:
> Hi David!
> On Mon, Jun 9, 2008 at 3:56 PM, David Huard <email@example.com> wrote:
> > One thing that you should know is that all "ufunc" (universal functions)
> > defined as functions operating on scalars. Numpy then wraps these
> > such that they can process ndarrays of any shape element by element. This
> > what is explained in the help(arctan2) documentation.
> I see the point for arctan and other functions with a single argument, but
> for arctan2, especially. It needs two arguments and if I want to
> compute the result of the vectors a=array([a1,a2]) and b=array([b1,b2])
> what I get is are the two results as if I would have written:
> array([ artcan2(a1,b1), arctan2(a2,b2) ]) #Note, this is NOT (a1,a2)
> or (b1,b2) !!
> If you know this and distribute your vector entries over two arrays, the
> broadcasting may be very useful. (As it is for many other functions!)
> It would be perhaps nice to call arctan2 with just ONE array argument
> and have a broadcasting like this:
> arctan2( array([[a1,a2],[b1,b2],[c1,c2]]) )
> --> array([arctan2(a1,a2), arctan2(b1,b2), arctan2(c1,c2) ] )
> and arctan2( array([x,y]) ) --> arctan2(x,y)
> > As for the example, maybe a way to avoid confusion would be to give an
> > example with scalar arguments first to show the basic behavior, and then
> > example using ndarray broadcasting.
> I would argue to show just the scalar version in the example and leave out
> the broadcasting version, because it makes less sense here, doesn't it?
> Is there any fancy matrix-or-whatever notation, that really makes up a
> good example for broadcasting with arctan2?
> PS: I am not against the current broadcasting scheme. It is perfectly ok.
> Scipy-dev mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Scipy-dev