习题6.5
1.代码实现
点击查看代码
import numpy as np
import networkx as nx
import pandas as pd
import pylab as plt
n=6
node=['v'+str(i) for i in range(1,n+1)]
A=np.zeros((n,n));A[0,[1,2]]=[2,7]
A[1,2:5]=[4,6,8]
A[2,[3,4]]=[1,3]
A[3,[4,5]]=[1,6];A[4,5]=3
G=nx.Graph(A)
d=nx.floyd_warshall_numpy(G)
dml=np.max(d,axis=0)
print('d=\n',d)
print('逐列最大值为:',dml)
f=pd.ExcelWriter('ti6_5.xlsx')
dd=pd.DataFrame(d)
num=np.array([[50,40,60,20,70,90]]).T
D=num*d
DD=pd.DataFrame(D)
sd=np.sum(D,axis=0)
sdm=min(sd)
ind=np.argmin(sd)
print('最小值为:',sdm)
print("达到最小值的地点为:",node[ind])
2.运行结果