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

查看:1196
本文介绍了在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中将复数的实部和虚部分开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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