如何以下列格式保存复杂数据?
0.0001760855-0.0000927256j
-0.0002311308+0.0000122892j
0.0002447444+0.0000968709j
-0.0002038497-0.0002121365j
0.0001077393+0.0003059170j
0.0000306011-0.0003521998j
-0.0001864669+0.0003330580j
0.0003283114-0.0002435598j
-0.0004244564+0.0000938909j
0.0004501374+0.0000918577j
但是使用numpy.savetxt(“path_to_array”,数组)我有这个:
(1.760855000000000135e-04+-9.272560000000000546e-05j)
(-2.311307999999999928e-04+1.228919999999999916e-05j)
(2.447444000000000008e-04+9.687089999999999438e-05j)
(-2.038497000000000009e-04+-2.121365000000000110e-04j)
(1.077393000000000003e-04+3.059170000000000053e-04j)
(3.060110000000000082e-05+-3.521997999999999817e-04j)
(-1.864668999999999951e-04+3.330580000000000086e-04j)
(3.283113999999999954e-04+-2.435597999999999919e-04j)
(-4.244564000000000041e-04+9.389090000000000597e-05j)
(4.501374000000000044e-04+9.185770000000000653e-05j)
请注意“(),+ - ,e-04”
答案 0 :(得分:3)
试试这个:
complex_array = [complex(0.0001760855-0.0000927256j),
complex(-0.0002311308+0.0000122892j),
complex(0.0002447444+0.0000968709j),
complex(-0.0002038497-0.0002121365j),
complex(0.0001077393+0.0003059170j)]
np.savetxt('tmp.txt', complex_array, fmt='%.10f%+.10fj')
tmp.txt:
0.0001760855-0.0000927256j
-0.0002311308+0.0000122892j
0.0002447444+0.0000968709j
-0.0002038497-0.0002121365j
0.0001077393+0.0003059170j