Reputation: 4023
I have a table with several columns and want save it with
numpy.savetxt('test.txt', test, fmt='%f')
I want save only the last column in float format, all other columns should be integers... For example
1 1 1 0.5
1 2 2 0.3
. . . .
How I can enlarge my savetxt function or use some alternative? Thank you in advance!
Upvotes: 1
Views: 1180
Reputation: 4005
If the number of columns is very large you can also do something like this:
numpy.savetxt('test.txt', test, fmt= '%d'*15 + '%f')
With this code, the first 15 columns are integers whereas the final column is a float.
Upvotes: 1
Reputation: 1500
fmt can be an array like so:
numpy.savetxt('test.txt', test, fmt=['%d', '%d', '%d', '%f'])
Upvotes: 5