在python中分离复数的实部和虚部 [英] separate real and imaginary part of a complex number in python

查看:112
本文介绍了在python中分离复数的实部和虚部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 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.

我有这个:

Y = (-5.79829066331+4.55640490659j)

我需要:

Z = (-5.79829066331, 4.55640490659)

如果有一种方法可以直接去而不通过Z,我也需要每个部分:

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

谢谢!

推荐答案

Y = (-5.79829066331+4.55640490659j)

Z = (Y.real, Y.imag)

A = Y.real
B = Y.imag


顺便说一句:

更多:Python:复数 - 实数和虚部

这篇关于在python中分离复数的实部和虚部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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