cmath模块为复数提供了有关数学运算函数,使得复数也能想整型或浮点型数字一样计算
复数极坐标系转换函数
在Python数据类型(一)数字类型中讲到复数的存储本质,和在极坐标系的定义,有关极坐标转换函数如下:
函数名 | 释义 |
---|---|
cmath.phase(x) | 以浮点数的形式返回x的弧度,范围在[-π,π] |
cmath.polar(x) | 返回x在极坐标系中的坐标(r,phi) |
cmath.rect(r, phi) | 返回坐标(r, phi)在极坐标系中对应的复数 |
>>> import cmath
>>> cmath.phase(complex(-1.0, 0.0))
3.141592653589793
>>> cmath.phase(complex(-1.0,0.0))
3.141592653589793
>>> cmath.phase(complex(-0.5, 0.0))
3.141592653589793
>>> cmath.phase(complex(-0.5, 0.3))
2.601173153319209
>>> cmath.polar(complex(-0.5, 0.3))
(0.58309518948453, 2.601173153319209)
&