Skip to content Skip to sidebar Skip to footer

How To Avoid Getting Imaginary/complex Number Python

I am using a python code, where one of the equations got sqrt root of negative value. I use cmath.sqrt to solve it. All answers I got from that equation are shown in imaginary/comp

Solution 1:

If I understand your question you either want

abs(z)

or

z.real

Solution 2:

If you want to drop the imaginary part from the value which you got after square root of any random number in python, so you can simply do:

value = sqrt(any number)

# for only real part
value = value.real

Post a Comment for "How To Avoid Getting Imaginary/complex Number Python"