Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

separate real and imaginary part of a complex number in python

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!

like image 681
litepresence Avatar asked Jul 06 '14 04:07

litepresence


People also ask

How do you extract real and imaginary part of complex numbers in Python?

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().

How do you separate complex numbers in Python?

Python3. Division of complex number: In Python, complex numbers can be divided using the / operator.

How do you get the imaginary part of a number in Python?

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.


1 Answers

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

like image 199
furas Avatar answered Sep 26 '22 00:09

furas