zoukankan      html  css  js  c++  java
  • networkx图的参数

     1 # Filename: stat_indictors.py
    2
    3 import networkx as nx
    4
    5 # generate a n = 1000, m = 3 BA scale-free network
    6 G = nx.random_graphs.barabasi_albert_graph(1000, 3)
    7 print G.degree(0) # return node0's degree
    8 print G.degree() # return all node's degree
    9 # return all node's distribution sequence, from 1 to max degree
    10 print nx.degree_histogram(G)
    11
    12 # add module matplotlib for drawing
    13 import matplotlib.pyplot as plt
    14 degree = nx.degree_histogram(G)
    15 # generate X scale sequence, from 1 to max degree
    16 x = range(len(degree))
    17 # transform the times to fequency
    18 y = [z / float(sum(degree)) for z in degree]
    19 # Distribution curve in double logarithmic axes
    20 plt.loglog(x, y, color = "blue", linewidth = 2)
    21 plt.show()
    22
    23 # calculate average Clustering coefficient
    24 print 'average clustering coefficient is ', nx.average_clustering(G)
    25 # calculate every node's clustering coefficient
    26 print "every node's clustering coefficient is ", nx.clustering(G)
    27
    28 # calucate Diameter of G (the length of the longest shortest path)
    29 print 'Diameter of G is ', nx.diameter(G)
    30 # calculate all nodes' average shortest path length
    31 print "all nodes' average shortest path length is", nx.average_shortest_path_length(G
  • 相关阅读:
    [WC2010]重建计划
    [POJ1741]Tree
    [NOI2008]志愿者招募
    [BZOJ2127]happiness
    「网络流 24 题」太空飞行计划
    [TJOI2015]线性代数
    [HDU2874]Connections between cities
    [POI2007]ZAP-Queries
    [SCOI2010]幸运数字
    POJ 2826 An Easy Problem?!
  • 原文地址:https://www.cnblogs.com/forstudy/p/2406916.html
Copyright © 2011-2022 走看看