I use networkx in ipython to analysis my graph or network, when I generated the maximum spanning tree and the minimum spanning tree, I got a very strange result that these two graph is the same! This is my code below:
a=nx.maximum_spanning_tree(pearson_net) b=nx.minimum_spanning_tree(pearson_net) pearson_net is my original network(graph), I want to get the edges of these two graph, but these edges are completely the same!
a.edges() This is the edges of graph a:
EdgeView([('600000.SH', '600015.SH'), ('600000.SH', '600016.SH'), ('600000.SH', '600030.SH'), ('600000.SH', '600036.SH'), ('600000.SH','600109.SH'), ('600000.SH', '600816.SH'), ('600000.SH','600837.SH'), ('600000.SH', '600999.SH'), ('600000.SH', '601009.SH'), ('600000.SH', '601099.SH'), ('600000.SH', '601166.SH'), ('600000.SH', '601288.SH'), ('600000.SH', '601318.SH'), ('600000.SH', '601328.SH'), ('600000.SH', '601336.SH'), ('600000.SH', '601377.SH'), ('600000.SH', '601398.SH'), ('600000.SH', '601555.SH'), ('600000.SH', '601601.SH'), ('600000.SH', '601628.SH'), ('600000.SH', '601688.SH'), ('600000.SH', '601788.SH'), ('600000.SH', '601818.SH'), ('600000.SH', '601939.SH'), ('600000.SH', '601988.SH'), ('600000.SH', '601998.SH'), ('600000.SH', '000001.SZ'), ('600000.SH', '000686.SZ'), ('600000.SH', '000728.SZ'), ('600000.SH', '000750.SZ'), ('600000.SH', '000776.SZ'), ('600000.SH', '000783.SZ'), ('600000.SH', '002142.SZ'), ('600000.SH', '002500.SZ'), ('600000.SH', '002673.SZ')]) and then
b.edges() These are the edges of graph b:
EdgeView([('600000.SH', '600015.SH'), ('600000.SH', '600016.SH'), ('600000.SH', '600030.SH'), ('600000.SH', '600036.SH'), ('600000.SH','600109.SH'), ('600000.SH', '600816.SH'), ('600000.SH','600837.SH'), ('600000.SH', '600999.SH'), ('600000.SH', '601009.SH'), ('600000.SH', '601099.SH'), ('600000.SH', '601166.SH'), ('600000.SH', '601288.SH'), ('600000.SH', '601318.SH'), ('600000.SH', '601328.SH'), ('600000.SH', '601336.SH'), ('600000.SH', '601377.SH'), ('600000.SH', '601398.SH'), ('600000.SH', '601555.SH'), ('600000.SH', '601601.SH'), ('600000.SH', '601628.SH'), ('600000.SH', '601688.SH'), ('600000.SH', '601788.SH'), ('600000.SH', '601818.SH'), ('600000.SH', '601939.SH'), ('600000.SH', '601988.SH'), ('600000.SH', '601998.SH'), ('600000.SH', '000001.SZ'), ('600000.SH', '000686.SZ'), ('600000.SH', '000728.SZ'), ('600000.SH', '000750.SZ'), ('600000.SH', '000776.SZ'), ('600000.SH', '000783.SZ'), ('600000.SH', '002142.SZ'), ('600000.SH', '002500.SZ'), ('600000.SH', '002673.SZ')]) I can not understand this result.Why maximum_spanning_tree is the same as minimum_spanning_tree?
This is the graph of pearson_net: 
It is a complete graph, one node can be linked with any other node. This is the part of the pearson_net'dataset below:
The columns and the index are the node of the graph, the number(pearson correlated coefficient) is the weight of the edge.
This is my complete code:
pearson_net=nx.Graph() for i in range(pearson): for j in range(i+1,pearson): pearson_net.add_edge(pearson.index[i],pearson.columns[j],...... weights=pearson.iloc[i][j]) tree1=nx.minimum_spanning_tree(pearson_net) tree2=nx.maximum_spanning_tree(pearson_net) "pearson" is the matrix of the correlated coefficient, which is the dataset before.





pearson_netlooks like.pearsonis a matrix but you are usingrange()on it. Can you try using thenx.from_numpy_matrix()function instead ?