Hello,
This is my first time working with Python and Networkx, and I'm having
problems with sorting nodes.
First of all I have an edge list based on the air traffic routes
around the world, I can read it and obtain the degree distribution,
but now i want to obtain the 25 nodes with highest degree. I use
"print GN.degree()" and obtain a large list of nodes and degrees, but
it's quite dirty doing it this way and I've thought to sort the nodes
in order of their degree and after that printing the first 25 on the
screen but I cannot do it. Anyone can give me a suggestion? I copy
here the code that I already have:
import networkx as nx
print 'llegim les dades de la xarxa global d aeroports '
print
GN=nx.read_edgelist("global-net.txt")
print 'calculem algunes propietats generals'
print
print
nx.info(GN)
print
print 'distribucio de grauss: '
print nx.degree_histogram(GN)
print
print 'grau maxim: '
print len(nx.degree_histogram(GN))-1
print
print 'grau mig calculat programant-ho'
degs=nx.degree(GN).values()
avgdegGN=0
for i in range(0,GN.order()):
avgdegGN = avgdegGN+degs[i]
print
print 'el grau mig calculat es:'
print (avgdegGN*1.0)/GN.order()
print
print '(compareu amb abans - aqui hi ha mes decimals - ) '
print
print 'El clustering coeficient promig esta implementat '
print 'pero tambe el podem calcular com es veu aqui'
###################################################################################################
# CLUSTERING COEFFICIENT
ClustC=nx.clustering(GN).values()
sumClust=0
maxCC=0
minCC=9
for i in range(1,GN.order()):
sumClust = sumClust + ClustC[i]
if ClustC[i]>maxCC:
maxCC= ClustC[i]
if ClustC[i]<minCC:
minCC=ClustC[i]
print
print 'Avg Clust Coeff. NetworkX = %-6.4f ' %
(nx.average_clustering(GN))
print
print 'Avg Clust Coeff. Calculat = %-6.4f ' % (sumClust/GN.order())
print
print '(minClust, maxClust) = (%-6.4f' % minCC,'- %-6.6f'% maxCC,')'
print
################################################################################
# FIND NODES WITH HIGHER DEGREE
print
'************************************************************************'
print
#print GN.degree()
sorted(GN.degree().values())
##print("Grau dels 25 mes grans")
##b = nx.degree(GN).values
##for v in range (0,24):
## print("%0.2d5.3f"%(v,b[v]))
Thank you all.