Question

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!

Was it helpful?

Solution

You could just simplify it:

"%03d" + "%.10f"*7
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top