问题
I want to save an array using numpy.savetxt
. The array contains eight numbers. Only the format of the first number is different with respect to the latter seven. I know I can set the format of numbers as follows:
numpy.savetxt(filename, array, fmt = "%03d" "%.10f" "%.10f" "%.10f" "%.10f" "%.10f" "%.10f" "%.10f")
Here filename
is just the name of my file e.g. numbers.dat
and array
is a 1D numpy array containing my eight numbers.
The above line of code works but looks ridiculous because I'm specifying each individual format of my numbers. How can I indicate that the latter seven numbers have the same format in a pythonic way?
Thx!
回答1:
You could just simplify it:
"%03d" + "%.10f"*7
来源:https://stackoverflow.com/questions/23117490/indicating-format-of-multiple-numbers-in-numpy-savetxt