having structured array :
[ (b'h', 0.9425, 0.1412, 7.1414) ... (b'n', 1.0037, 4.0524, 6.8000)]
i want make .txt file
using numpy.savetxt
each element of array written in separate line:
h 0.9425 0.1412 7.1414 n 1.0037 4.0524 6.8000
i set newline='\n'
doesn't work , elements written in single line. same problem header parameter, specified header printed in same line.
now looks this:
29shifts: 1.0 3.0 7.0b'c' 1.0029 3.5098 7.9883 b'n' 1.0039 4.0586 6.8008 29shifts: 1.0 4.0 0.0b'c' 1.0029 4.5078 0.9873 b'n' 1.0039 5.0586 -0.2000 29shifts: 1.0 5.0 9.0b'c' 1.0029 5.5078 9.9844 b'n' 1.0039 6.0586 8.7969
here parameters used:
np.savetxt(outfile, recarray, fmt=[b'%s','%-7.4f','%-7.4f','%-7.4f'], delimiter=' ', newline='\n', header='29\nshifts: 1.0 1.0 3.5\n', comments='')
thank you
i wonder if there's problem \n
on system; maybe python using 1 value, while file viewer expecting (there dos, linux, , mac standards).
i have no problem data , format in ipython session on linux machine.
in [88]: d=[ (b'h', 0.9425, 0.1412, 7.1414),(b'n', 1.0037, 4.0524, 6.8000)] in [89]: data=np.array(d,'|s1,f,f,f') in [90]: data out[90]: array([(b'h', 0.9424999952316284, 0.1412000060081482, 7.14139986038208), (b'n', 1.0037000179290771, 4.0524001121521, 6.800000190734863)], dtype=[('f0', 's1'), ('f1', '<f4'), ('f2', '<f4'), ('f3', '<f4')]) in [91]: np.savetxt('test.txt', data,fmt =[b'%s','%-7.4f','%-7.4f','%-7.4f']) in [92]: cat test.txt b'h' 0.9425 0.1412 7.1414 b'n' 1.0037 4.0524 6.8000 in [93]np.savetxt('test.txt', data,fmt=[b'%s','%-7.4f','%-7.4f','%-7.4f'], delimiter=' ', newline='\n', header='29\nshifts: 1.0 1.0 3.5\n', comments ='') in [94]: cat test.txt 29 shifts: 1.0 1.0 3.5 b'h' 0.9425 0.1412 7.1414 b'n' 1.0037 4.0524 6.8000
Comments
Post a Comment