问题描述
我正在使用python代码,其中一个方程式的平方根为负。我使用 cmath.sqrt
来解决它。我从该方程式获得的所有答案均以虚/复数形式显示(例如x.xxxxx j )。我不想得到那个虚/复数,因为我随后使用的代码无法读取那些虚/复数。因此,如何避免不得到虚数?或以其他方式,如何将这些虚数转换为实数?或如何删除那些 j。谢谢。
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.
推荐答案
如果我理解您的问题,您要么想要
If I understand your question you either want
abs(z)
或
z.real
这篇关于如何避免获得虚数/复数python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!