Search code examples
pythonnumpyphasecmath

Different functions for calculating phase/argument of complex numbers


Are there any differences between the

cmath.phase()

function from the cmath module, and the

np.angle()

function from numpy.


Solution

  • Mathematically, there is no difference between these two functions. Both compute the phase or argument of a complex number as:

    arg = arctan2(zimag, zreal)
    

    See documentation for cmath.phase and source code for numpy.angle. From software point of view, as @Julien mentioned in his comment, cmath.phase() will not work on numpy.ndarray.