Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python - retrieve unconnected node pairs

nodelist = list(G0.nodes(data=True))                        # From G to list
vertex = [a for a, b in nodelist]                           # Get attribute vertex
node_df = pd.DataFrame({'vertex': vertex})                  # Get DF with vertex
node_list = node_df["vertex"].tolist()                      # From df to list

node_list = list(dict.fromkeys(node_list))                  # Remove duplicate items from the list
adj_G = nx.to_numpy_matrix(G0, nodelist = node_list)        # Build adjacency matrix


all_unconnected_pairs = []                                                  
offset = 0                                                                  
for i in tqdm(range(adj_G.shape[0])):                                       # Take only above diagonal of the adjacency matrix                                         
  for j in range(offset, adj_G.shape[1]):
    if i != j:
        # if G0[node_list[i], node_list[j]]['weight'] <=2:                  # Take only edges with weight 1 or 2
            if adj_G[i,j] ==0:                                              # Take only unconnected node pairs                                     
                all_unconnected_pairs.append([node_list[i], node_list[j]])

  offset = offset + 1

len(all_unconnected_pairs)  

Comment

PREVIOUS NEXT
Code Example
Python :: ist comperension python 
Python :: jupyter notebook morse code francais 
Python :: python copy formula ghseets 
Python :: convert code c++ to python online 
Python :: how to add twoo segmen time series in a single plot 
Python :: python converter to c 
Python :: how to use list compression with conditional formatting 
Python :: Kernel Ridge et Hyperparameter cross validation sklearn 
Python :: command to update pip 
Shell :: FirewallD is not running 
Shell :: how to delete dangling docker images 
Shell :: check supervisord status 
Shell :: how to install pil in anaconda 
Shell :: ubuntu media codecs 
Shell :: upgrade matplotlib version 
Shell :: conda install keras 
Shell :: chrome update ubuntu 20.04 
Shell :: mysqlclient install ubuntu 
Shell :: linux check ram frequency 
Shell :: how pip install on centos 
Shell :: cond install opencv 
Shell :: clean manjaro 
Shell :: pip install beautiful soup 
Shell :: debian install killall 
Shell :: apache disable autostart linux 
Shell :: linux show version 
Shell :: ps1 file not digitally signed 
Shell :: ubuntu du sort by dir size 
Shell :: uninstall webpack globally 
Shell :: update vs code in ubuntu 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =