question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The phase of 0 is not defined, but numpy.angle(0) works

See original GitHub issue

numpy.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:closed
  • Created 8 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mhvkcommented, Apr 21, 2015

Agreed that it would be better to document it rather than return NaN or an exception. A similar problem occurs with np.arctan2(0.,0.) (also returns 0). 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 a NaN 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.)

0reactions
lebigotcommented, Apr 14, 2020

This is good, thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does numpy.angle(0+0j) answer pi instead of zero
Although the angle of the complex number 0 is undefined, numpy.angle(0) returns the value 0. This seems to be incorrect if the real...
Read more >
numpy.unwrap — NumPy v1.24 Manual
If the discontinuity in p is smaller than period/2 , but larger than discont, no unwrapping is done because taking the complement would...
Read more >
Numerical Methods using Python (scipy)
Using scipy's quad function, write a program that solves the following integral numerically: I = ∫10cos(2πx)dx. Find the analytical integral and compare it ......
Read more >
How to Fix: NameError name 'np' is not defined - Statology
This tutorial explains how to fix the following error in Python: NameError name 'np' is not defined, including several examples.
Read more >
Built-in Functions — Python 3.11.1 documentation
If x is not a Python int object, it has to define an __index__() method ... The bytearray class is a mutable sequence...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found