python 数组写入txt文档(数据之间用逗号分离)

python 数组写入txt文档(数据之间用逗号分离),第1张

import codecs
import numpy as np
text =np.zeros((3, 3))

str1 = u'新数据:\r\n'
f = codecs.open("text.txt",'w','utf-8')

f.write(str1)
for i in range(0,text.shape[0]):
    for j in range(text.shape[1]):
       f.write(str(text[i,j])+',')
    f.write('\r\n')
f.close()

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/916779.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-16
下一篇 2022-05-16

发表评论

登录后才能评论

评论列表(0条)

保存