numpy.savetxt在标题行的开头没有哈希标记

时间:2022-08-01 21:22:28

When I try to save a matrix with header, a hash mark and a space (# ) appear on the first line:

当我尝试使用标题保存矩阵时,第一行会出现哈希标记和空格(#):

input:

np.savetxt(filename,data, fmt='%i %i %i %i %s',delimiter='\t',header="a\tb\tc\td\te")

output:

# a b   c   d   e
0   0   0   0   bla
0   0   0   0   bla
1   1   1   1   bla
1   1   1   1   bla

Any hint why? How could I remove it?

任何暗示为什么?我怎么能删除它?

1 个解决方案

#1


32  

it inserts the # because that line is a comment, and the default character for comments is the symbol #, as you can read in the documentation here.

它插入#,因为该行是注释,注释的默认字符是符号#,您可以在此处的文档中阅读。

If you want to get rid of it, pass comments='' as option to savetxt.

如果你想摆脱它,传递comments =''作为savetxt的选项。

#1


32  

it inserts the # because that line is a comment, and the default character for comments is the symbol #, as you can read in the documentation here.

它插入#,因为该行是注释,注释的默认字符是符号#,您可以在此处的文档中阅读。

If you want to get rid of it, pass comments='' as option to savetxt.

如果你想摆脱它,传递comments =''作为savetxt的选项。