python 存 numpy数组进 Excel
还是今年研究生数模的时候用到的
import xlwt
import numpy as np
def saveMatrix2Excel(data, path):
f = xlwt.Workbook() # 创建工作簿
sheet1 = f.add_sheet(u'sheet1', cell_overwrite_ok=True) # 创建sheet
[h, l] = data.shape # h为行数,l为列数
for i in range(h):
for j in range(l):
sheet1.write(i, j, data[i, j])
f.save(path)
W =[[1,2,3,4],[5,6,7,8]]
pathW = "w.xls" # 保存在当前文件夹下,你也可以指定绝对路径
saveMatrix2Excel(W,pathW)
简单实用