wting / python-graph

Automatically exported from code.google.com/p/python-graph
Other
5 stars 4 forks source link

Get and count node neighbors #122

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I am trying to read a file with node pairs and weight. I have to find the 
neighbours of each pair individual and combined both also count them. Later 
find the ratio of the neighbours that each node has. I am stuck with finding 
nodes.

infile.txt

0_node1 0_node2 0w
1_node1 1_node2 1w
2_node1 2_node2 2w
3_node1 3_node2 3w
4_node1 4_node2 4w

import networkx as nx
import matplotlib.pyplot as plt

G=nx.Graph()
G = nx.read_edgelist('infile.txt', data=[("weight", float)])

def get_triangle(G):
  for n1 in G.nodes:
  neighbors1 = set(G[n1])
  for n2 in filter(lambda x: x>n1, nodes):
    neighbors2 = set(G[n2])
    common = neighbors1 & neighbors2
    for n3 in filter(lambda x: x>n2, common):
     print n1
     print n2
     print n3

No Erorrs No output 

Original issue reported on code.google.com by phani....@gmail.com on 17 Jul 2014 at 3:24