The phase of 0 is not defined, but numpy.angle(0) works
See original GitHub issuenumpy.angle(0)
returns 0.0.
However, in mathematics, 0 does not have any angle. I would have expected feeding 0 to numpy.angle()
to raise an exception (or maybe generate NaN??).
Now, the standard cmath
library has a similar function, except that it is called phase()
. This function does return a 0 phase for 0 (unlike a mathematical phase). However, this behavior is documented.
Thus, at the very least, the behavior of numpy.angle()
for 0 should be defined in the documentation.
Since the current behavior is not officially documented yet, and since the name of the function is different from the similar cmath.phase()
name, maybe NumPy has the opportunity to produce a more mathematically correct result for 0, like raising an exception or maybe returning NaN?
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
Agreed that it would be better to document it rather than return
NaN
or an exception. A similar problem occurs withnp.arctan2(0.,0.)
(also returns0
). But often when one does these types of calculation, the radius is also calculated and the angle later simply does not matter; it would be annoying if aNaN
were returned and further calculations would start to fail. (E.g., suppose I have a large range of X,Y; I’d want conversion to polar and back to give me back my X,Y.)This is good, thanks.