문제

I am saving some data with numpy.savetxt(path,array,fmt="%.2f %.2f %.2f %.2f %.2f") and I want the text file to be formated nicely. I would like to limit the floats to a certain amount of digits, like this:

11.2345 -> 11.2
1.2345 -> 1.23

Currently I get:

11.2345 -> 11.23
1.2345 -> 1.23

This destroys the layout of the text file.

I know that there are a couple of similar questions on SO, however I was not able to apply any of the solutions to numpy.savetxt().

도움이 되었습니까?

해결책

Try using fmt="%9.2f". It seems to give nice results for me:

    25.72    433.54    135.69    898.93
   177.46    120.65    954.13    480.82
   963.45    774.35    289.08     93.64
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top