Add numpy.phase in addition to numpy.angle
See original GitHub issueI wanted to suggest adding a function which directly gives the phase of a complex valued number instead of the angle:
def phase(z): # Calculates the phase of a complex number
r = numpy.absolute(z)
return (z.real/r + 1j * z.imag/r)
This is a simple enhancement, which I think would make numpy more consistent and offer the benefit of simply being faster in large loops, rather than going the ang = numpy.angle(z); phase = numpy.cos(ang) + 1j * numpy.sin(ang)
route (or numpy.cos(1j * ang)
, for what it’s worth).
Issue Analytics
- State:
- Created 10 years ago
- Comments:13 (13 by maintainers)
Top Results From Across the Web
numpy.angle — NumPy v1.24 Manual
A complex number or sequence of complex numbers. degbool, optional. Return angle in degrees if True, radians if False (default). Returns:.
Read more >Possible Bug in Numpy Complex Phase Angle Handling
There are two simple ways of implementing this: The first is to write each as a complex array and add them. The second...
Read more >numpy.angle() in Python - GeeksforGeeks
numpy.angle() function is used when we want to compute the angle of the complex argument. A complex number is represented by “ x...
Read more >Python - Get the Phase Angle of a Complex Number
To get the phase of a complex number in degrees, pass deg=True as an argument to the numpy.angle() function. Let's use the same...
Read more >Complex Numbers
Python offers the built-in math package for basic processing of complex numbers. ... Geometrically, the product is obtained by adding angles and by ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, if my guess is right and no-one uses that, then no-one will complain if we transition it… it’d take a few releases still to follow the deprecation cycle but it might be best to ask people to just write ‘z / np.abs(z)’ until 1.11 or whatever, rather than add a new function to the namespace?
On Thu, Aug 15, 2013 at 9:48 PM, Charles Harris notifications@github.comwrote:
I don’t have a strong opinion either way, just raising the issue. Having a plethora of confusingly similar functions should be avoided though…
what the heck does our sign function do for complex numbers? Is this like cmp(z, 0) with lexicographic order? Is that actually useful to anyone and could we change it to this much more sensible definition?
(numpy.linalg.slogdet is one function that uses the abs(z) == 1 definition of sign for complex numbers.)
On Thu, Aug 15, 2013 at 2:38 PM, Charles Harris notifications@github.comwrote: