Follow-up to: Complex numbers, abs resluts in ...
noyb
soufle at yahoo.com
Mon Nov 11 14:04:26 EST 2002
I had previously posted the following:
**************************
I am trying to find out how to get the phase or angle of a complex
number in Python 2.2. Yes, I have Numpy installed.
I have found how to get the magnitude of a complex number, use "abs".
I have also found how to get the real and imaginary parts but am
stumped by the angle.
I am using something like:
my_complex_variable = (a +bj)
and I can do
abs(my_complex_variable)
to get the magnitude.
I realize the angle is atan(b,a) but I need to use my_complex_variable
as input and not a,b.
Hope someone knows of a comand I am missing.
David
****************************
and Alex kindly replied:
****************************
import math
def phase(mcv):
return math.atan2(mcv.imag, mcv.real)
I don't think there's any Python built-in that does this.
Alex
****************************
I should have explained that "mcv" is a rank 1 array and not a scalar.
atan2 does not seem to accept anything other than a scalar. Is a
"for"
loop in my future?
David
(python neophyte)
More information about the Python-list
mailing list