0

How I can save complex data in this following format?

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 

But with numpy.savetxt("path_to_array", array) I have this:

(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) 

Note the "(),+-, e-04"

2
  • Many options here such as fmt. Commented Mar 13, 2017 at 13:32
  • with: fmt="%7.10f+%7.10f" I have 0.0001760855+-0.0000927256 (note the +-) Commented Mar 13, 2017 at 13:34

1 Answer 1

3

Try this:

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 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.