1

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!

2 Answers 2

5

fmt can be an array like so:

numpy.savetxt('test.txt', test, fmt=['%d', '%d', '%d', '%f'])
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.