Python Forum
issue with numpy.savetxt - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: issue with numpy.savetxt (/thread-11513.html)



issue with numpy.savetxt - alyssaantarctica - Jul-12-2018

I'm trying to save the following in a txt file:

relmax = [ 6.9251146   7.23467703 10.5914501 ]
relmin = [ 7.10074018  8.9889703  12.6603858 ]
However, the file saves with the 10.59 etc as 1.059 and the 12.660 etc as 1.2660. What's happening? The code I'm using for savetxt is
np.savetxt('sat 10 relative extrema', np.transpose([relmax, relmin]), delimiter='   ', header = 'time of apicenters, time of pericenters')
Thanks


RE: issue with numpy.savetxt - Larz60+ - Jul-13-2018

I think (I am by no means an expert at this) that you need to use a fmt string to specify the value format:

Output:
fmt : str or sequence of strs, optional A single format (%10.5f), a sequence of formats, or a multi-format string, e.g. ‘Iteration %d – %10.5f’, in which case delimiter is ignored. For complex X, the legal options for fmt are: a. a single specifier, fmt=’%.4e’, resulting in numbers formatted like ‘ (%s+%sj)’ % (fmt, fmt) b. a full string specifying every real and imaginary part, e.g. ‘ %.4e %+.4ej %.4e %+.4ej %.4e %+.4ej’ for 3 columns c/ a list of specifiers, one per column - in this case, the real and imaginary part must have separate specifiers, e.g. [‘%.3e + %.3ej’, ‘(%.15e%+.15ej)’] for 2 columns