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.

Add numpy.phase in addition to numpy.angle

See original GitHub issue

I 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:closed
  • Created 10 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
njsmithcommented, Aug 15, 2013

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:

Yep, that is what it does 😉 I don’t know that we can just change it, OTOH, I doubt many use the current form for complex.

— Reply to this email directly or view it on GitHubhttps://github.com/numpy/numpy/issues/3621#issuecomment-22729122 .

1reaction
njsmithcommented, Aug 15, 2013

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:

@njsmith https://github.com/njsmith Some folks use that as the signfunction for complex, so it might be worth having.

— Reply to this email directly or view it on GitHubhttps://github.com/numpy/numpy/issues/3621#issuecomment-22703179 .

Read more comments on GitHub >

github_iconTop 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 >

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