How to avoid getting imaginary/complex number python

我的未来我决定 提交于 2019-12-13 09:13:33

问题


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/complex number (e.g. x.xxxxxj). I don't want to get that imaginary/complex number as the code that I use subsequently cannot read those imaginary/ complex number. As such, how can I avoid not to get imaginary numbers? OR in other way, how can I convert those imaginary number into real ones? or how can I remove those "j". Thanks.


回答1:


If I understand your question you either want

abs(z)

or

z.real


来源:https://stackoverflow.com/questions/37246418/how-to-avoid-getting-imaginary-complex-number-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!