1

I have a Numpy array of

a=[[ 9.9888e-01   7.6924e-04   3.5270e-04]
   [ 7.6924e-04   9.9888e-01   3.5270e-04]]

I would like to write it to file with six decimal point precision. I know that it is possible to print it to console using "%.6f", but how can I write it to file in below format:

[[  0.998878   0.000769   0.000353]
 [  0.000769   0.998878   0.000353]]

Could you tell me how to do this, please. Thanks in advance!

1 Answer 1

2

You can use the same format code as the fmt parameter of np.savetxt

np.savetxt('test.out', a, fmt = '%.6f')
Sign up to request clarification or add additional context in comments.

1 Comment

Yes,exactly, why I did not consider np.savetext. Thank you @Daniel F

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.