python计算熵值法计算实例

import csv
csv_file =csv.reader(open('1.csv','r'))
print(csv_file)
for s in csv_file:
    print(s)
import numpy as np
print(csv_file)
np1 = np.loadtxt(open("1.csv","rb"),delimiter=",",skiprows=0)#原始数据
print(np1)
a=np.sum(np1)
a=np.sum(np1,0)#列求和矩阵
print(a)
b=np1/a#运算
print(b)

c=b*np.log(b)#运算
print(c)
k=1/np.log(4)#注意,4方案数
print(k)
d=-k*np.sum(c,0)#运算
print(d)
e=1-d#运算
print(e)
f=e/np.sum(e)#运算
print(f)
#---------------------------------------------
import csv
csv_file =csv.reader(open('2.csv','r'))
print(csv_file)
for s in csv_file:
    print(s)
import numpy as np
print(csv_file)
np0= np.loadtxt(open("2.csv","rb"),delimiter=",",skiprows=0)#原始数据
np1=np0+0.0000001
print(np1)
a=np.sum(np1)
a=np.sum(np1,0)#列求和矩阵
print(a)
b=np1/a#运算
print(b)

c=b*np.log(b)#运算
print(c)
k=1/np.log(96)#注意,4方案数
print(k)
d=-k*np.sum(c,0)#运算
print(d)
e=1-d#运算
print(e)
f=e/np.sum(e)#运算
print(f)
for i in f:
    print(i)

 

你可能感兴趣的:(python计算熵值法计算实例)