【发布时间】:2019-08-09 13:42:03
【问题描述】:
我想将复数和实数部分四舍五入到小数点后 2 位。我如何在 python 中做到这一点?
angle = 2 * np.pi *2
c1 = complex(np.cos(angle),np.sin(angle))
c1 = round(c1,2)
【问题讨论】:
-
如果您只想显示圆角:
f"{c1:.2}"或"{:.2}".format(c1)。 -
complex(round(c1.real,2), round(c1.imag, 2)) -
x = complex(round(x.real,2), round(x.imag,2)) -
我没有在矩阵中使用这些复数。为了便于阅读,我希望将其显示到小数点后 2 位
-
@Rick
.2将其四舍五入到两位的精度(例如,1.23被四舍五入为1.2),而不是两位小数。可以考虑使用.2f。
标签: python numpy rounding complex-numbers