[excel]矩阵生成与导入
#coding=utf-8
import numpy as np
import xlrd
def import_excel_matrix(path):
table = xlrd.open_workbook(path).sheets()[0] # 获取第一个sheet表
row = table.nrows # 行数
col = table.ncols # 列数
datamatrix = np.zeros((row, col)) # 生成一个nrows行*ncols列的初始矩阵
for i in range(col): # 对列进行遍历
cols = np.matrix(table.col_values(x)) # 把list转换为矩阵进行矩阵操作
datamatrix[:, x] = cols # 按列把数据存进矩阵中
return data_matrix
data_file = u'C:\\Users\\hxy\\Desktop\\单参数表.xlsx' # Excel文件存储位置
import_excel_matrix(data_file)

浙公网安备 33010602011771号