level 1
import numpy as np
import xlrd
import math
myfile = xlrd.open_workbook(r'C:\Users\vincen\Desktop\data1.xlsx')
sheets = myfile.sheet_names()
print(sheets)
sheet1=myfile.sheet_by_name('红葡萄酒决策矩阵')
sheet2=myfile.sheet_by_name('白葡萄酒决策矩阵')
print(sheet1.name,sheet1.nrows,sheet1.ncols)
print(sheet2.name,sheet2.nrows,sheet2.ncols)
n=sheet1.nrows
m=sheet1.ncols
array= np.zeros((27,10))
for i in range(27):
rows = sheet1.row_values(i)
for j in range(10):
array[i][j]=rows[j]
sum=0
for i in range(27):
for j in range(10):
sum+=array[i][j]
for i in range(27):
for j in range(10):
array[i][j]=array[i][j]/sum
array1=np.zeros(10)
sum1=np.zeros(10)
array2=np.zeros((27,10))
for i in range(27):
for j in range(10):
array2[i][j]=(math.log(array[i][j]))*array1[i][j]
j=0
while(j<10):
for i in range(27):
sum1[j]+=array2[i][j]
k=1/math.log(n)
H=np.zeros(10)
sumH=np.zeros(10)
d=np.zeros(10)
for i in range(10):
H[i]=-k*sum1[i]
i=0
while(i<10):
sumH+=H[i]
for i in range(10):
d[i]=(1-H[i])/(m-sumH)
print(d)
2018年08月17日 16点08分