算法步骤
Python代码
import numpy as np
def diagonal_complete(D):
D = D.astype('float')
inf = np.inf
for i in range(D.shape[0]):
D[i, i] = inf
H = []
row_extract, column_extract = range(D.shape[0]), range(D.shape[0])
D_extract = D.copy()
k_iter = 1
while 1:
N = D_extract.shape[0]
Ri = []
for i in range(N):
Ri.append(np.min(D_extract[i]))
D_extract[i] -= Ri[i]
Rj = []
for i in range(N):
Rj.append(np.min(D_extract[:, i]))
D_extract[:, i] -= Rj[i]
Pi, Pj = [], []
for i in range(N):
t = sorted(D_extract[i])
Pi.append(t[1] - t[0])
t = sorted(D_extract[:, i])
Pj.append(t[1] -