Python output numpy array to csv

1 Function Detailsnumpy.savetxt

store the array in a text file

numpy.savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', 
header='', footer='', comments='# ', encoding=None)
***参数***
# fname:文件名
# X:1维或者2维数组
# delimiter:用于分割列的字符/字符串
# newline:于分割行的字符/字符串
# header:写入开头的字符串
# footer:写入结尾的字符串
# comments:将在页眉和页脚字符串前加前缀的字符串,以将它们标记为注释。默认值:“#”
# encoding:用于对输出文件进行编码的编码
# fmt:字符串输出格式
# %[flag]width[.precision]specifier

Detailed explanation of fmt format
%[flag]width[.precision]specifier

  • flags:
    insert image description here
  • width:
    insert image description here
  • precision:
    insert image description here
  • specifiers:
    insert image description here

2 Save numpy array as csv file

Precautions:

  1. The file extension is csv
  2. delimiter is set to ","
import numpy as np
np.savetxt('test.csv',data,delimiter=",")

Learning link:

Guess you like

Origin blog.csdn.net/weixin_45913084/article/details/130053691