-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnet_graph.py
48 lines (32 loc) · 825 Bytes
/
net_graph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# coding: utf-8
# In[1]:
import networkx as nx
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# In[21]:
def net_graph():
all_members = set(range(11))
G = nx.Graph()
G.add_nodes_from(all_members)
G.name = "asking for an opinion"
netdat = """ 0 1 1 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0
1 1 0 1 0 1 1 1 0 0 0
0 0 0 0 0 0 1 1 0 0 0
0 1 0 1 0 1 1 1 0 0 0
0 1 0 1 1 0 1 1 0 0 0
0 0 0 1 0 0 0 1 1 0 1
0 1 0 1 0 0 1 0 0 0 1
0 0 0 1 0 0 1 1 0 0 1
1 0 1 1 1 0 0 0 0 0 0
0 0 0 0 0 1 0 1 1 0 0"""
for row, line in enumerate(netdat.split('\n')):
thisrow = [int(b) for b in line.split()]
for col, entry in enumerate(thisrow):
if entry == 1:
G.add_edge(row, col)
return G
G = net_graph()
# In[29]:
#net_graph().nodes