Click here to Skip to main content
15,065,914 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this is a function for degree centrality using netwrokx, I need to write a function for degree centrality without using netwrokx

What I have tried:

```
<pre>def degree_centrality(email, nodes):
    top = set(nodes)
    bottom = set(email) - top
    s = 1.0/len(bottom)
    centrality = dict((n,d*s) for n,d in G.degree_iter(top))
    s = 1.0/len(top)
    centrality.update(dict((n,d*s) for n,d in G.degree_iter(bottom)))
    return centrality

```
Posted
Comments
Richard MacCutchan 26-May-21 16:28pm
   
Ok, please feel free to go ahead and write it.
Rawan Kawtharani 27-May-21 14:54pm
   
```
def degree_centrality(G):
top = set(G.nodes())
bottom = set(G.edges()) - top
s = 1.0/len(bottom)
centrality = dict((n,d*s) for n,d in G.edges(top))
s = 1.0/len(top)
centrality.update(dict((n,d*s) for n,d in G.edges(bottom)))
return centrality
degree_centrality(G)
```
I wrote this code but dosn't give the accurate result, plz can you help me to fix it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900