I have need to extract the real and imaginary elements of a complex number in python. I know how to make a list into a complex number... but not the other way around.
I have this:
Y = (-5.79829066331+4.55640490659j)
I need:
Z = (-5.79829066331, 4.55640490659)
and I will also need each part if there is a way to go directly without going by way of Z:
A = -5.79829066331 B = 4.55640490659
https://docs.python.org/2/library/functions.html#complex
Thanks!
An complex number is represented by “ x + yi “. Python converts the real numbers x and y into complex using the function complex(x,y). The real part can be accessed using the function real() and imaginary part can be represented by imag().
Python3. Division of complex number: In Python, complex numbers can be divided using the / operator.
In Python, the imaginary part can be expressed by just adding a j or J after the number. We can also use the built-in complex() function to convert the two given real numbers into a complex number.
Y = (-5.79829066331+4.55640490659j) Z = (Y.real, Y.imag) A = Y.real B = Y.imag
BTW:
More: Python: Complex number - real and imaginary part
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With