Numble savetxt does not add comma delimiter

numble savetxt does not add comma delimiter

I have an array with the following contents:

3.880631596916139792e-01 6.835074831218364011e-01 4.604322858429276133e-01 3.494236368132551673e-01 7.142120448019100287e-01 2.579415438181463793e-01 8.230159985476581674e-01 7.342531681855216652e-01 3.196536650498674748e-01 7.444435819161493439e-01 

And I save it as follows:

  np.savetxt('x.train.1.txt',XTraining, delimiter=',') 

However, when I look in the txt file, there are no commas.

+6
source share
2 answers

I assume the default case is to save a list of lists, so you need to either treat it as a list of only one list:

 np.savetxt('x.train.1.txt',[XTraining], delimiter=',') 

Or put a comma instead of new lines (note: this adds a trailing comma)

 np.savetxt('x.train.1.txt',XTraining, newline=',') 
+5
source

If you want them to be on separate lines and separated by commas

 np.savetxt('x.train.1.txt', XTraining[None, :], delimiter=',\n') 
+2
source

Source: https://habr.com/ru/post/1014732/


All Articles