[Numpy-discussion] Problem with np.savetxt

Stephen P. Molnar s.molnar at sbcglobal.net
Tue Oct 8 13:53:51 EDT 2019


Thanks for the replies. All is now well!

I'm thankful that this list is so very patient with ROF's (retired old 
fools) struggling to learn a new programmng language.


On 10/08/2019 10:42 AM, Fabrice Silva wrote:
> Le mardi 08 octobre 2019, Stephen P. Molnar a ?crit :
>>> data = np.genfromtxt("13-7.log", usecols=(1), dtype=None,
>>> skip_header=27, skip_footer=1, encoding=None)
>>> print(data)
>>> [...]
>>> ['-8.839713733' '-8.743377250' '-8.151051167' '-8.090452911'
>>>    '-7.967494477' '-7.854890056' '-7.757417879' '-7.741557490'
>>>    '-7.643885488' '-7.611595767' '-7.507605524' '-7.413920814'
>>>    '-7.389408331' '-7.384446364' '-7.374206276' '-7.368808179'
>>>    '-7.346641418' '-7.325037898' '-7.309614787' '-7.113209147']
>
> Hi,
> Note that your *data* array is made of strings and not floats.
> The default value of the *dtype* argument is *float*, which you 
> override by *None.*
> Remove the 'dtype=None' part to correctly load data
>
> You then have no problem to save your data with the format you want.
>
> Fabrice
>
> PS : be aware that [data] is a 2D row array, that will end up inlined 
> with command
> np.savetxt('13-7', [data], fmt='%15.9f', header='13-7')
> Remove the bracket for a one-per-line formatted output
> np.savetxt('13-7', data, fmt='%15.9f', header='13-7')
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion

-- 
Stephen P. Molnar, Ph.D.
www.molecular-modeling.net
614.312.7528 (c)
Skype:  smolnar1

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20191008/e29ac854/attachment.html>


More information about the NumPy-Discussion mailing list