如何避免获得虚数/复数python [英] How to avoid getting imaginary/complex number python

查看:276
本文介绍了如何避免获得虚数/复数python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆