Python Forum
issue with numpy.savetxt
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
issue with numpy.savetxt
#1
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
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Numpy] How to store different data type in one numpy array? water 7 302 Mar-26-2024, 02:18 PM
Last Post: snippsat
  Numpy returns "TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'int'" kalle 2 2,530 Jul-19-2022, 06:31 AM
Last Post: paul18fr
  Help with simplifying a code + np.savetxt() Laplace12 3 2,335 Jul-21-2020, 06:37 AM
Last Post: scidam
  numpy.str bytes issue jrmusiov 0 1,540 Jan-21-2020, 07:09 PM
Last Post: jrmusiov
  memory issue loading movie to numpy array djf123 1 2,247 Nov-07-2019, 06:19 AM
Last Post: ThomasL
  "erlarge" a numpy-matrix to numpy-array PhysChem 2 2,934 Apr-09-2019, 04:54 PM
Last Post: PhysChem

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020