[Numpy-discussion] how do I specify maximum line length when using savetxt?

Derek Homeier derek@astro.physik.uni-goettingen...
Wed Dec 5 18:27:42 CST 2012


On 06.12.2012, at 12:40AM, Mark Bakker wrote:

> I guess I wasn't explicit enough.
> Say I have an array with 100 numbers and I want to write it to a file
> with 6 numbers on each line (and hence, only 4 on the last line).
> Can I use savetxt to do that?
> What other easy tool does numpy have to do that?

I've just been looking into a similar case and I think there is no easy tool
for this - i.e. nothing comparable to Fortran's '(6e10.3)' or the like, so if
your array does not reshape to a Nx6 array, you'd probably have to write
something customised yourself. I would not be terribly difficult to add such
functionality to savetxt, but then, unless you want the output file to be more
human-readable, there is not really a strong case for writing a shape (100,)
array into 16 lines plus an incomplete one - it just would not play well with
reading back in and then determining the right shape automatically…

HTH,
					Derek




More information about the NumPy-Discussion mailing list