1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| import numpy as np
data = np.array([ [9,0,0,0], [8,3,0.9,0.5], [6,7,0.2,1] ])
def mlog(x): l = len(x) res = [] for i in x: if i == 0: res.append(0) else: res.append(np.log(i)) return np.array(res)
Z = data / np.sqrt(np.sum(data*data,axis=0)) print("标准化矩阵为:",Z)
P = Z / np.sum(Z,axis=0)
n,m = P.shape d = [] for i in range(m): x = P[:,i] e = -np.sum(x*mlog(x))/np.log(n) d.append(1-e) d = np.array(d)
w = d/np.sum(d) print("权重为:",w)
s = np.dot(Z,np.reshape(w,(-1,1))) for i in s: print("各评分为:",i)
|