Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74645 > unrolled thread
| Started by | lavanya addepalli <phani.lav@gmail.com> |
|---|---|
| First post | 2014-07-17 17:39 +0200 |
| Last post | 2014-07-17 17:39 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
New to Python and Python mail List lavanya addepalli <phani.lav@gmail.com> - 2014-07-17 17:39 +0200
| From | lavanya addepalli <phani.lav@gmail.com> |
|---|---|
| Date | 2014-07-17 17:39 +0200 |
| Subject | New to Python and Python mail List |
| Message-ID | <mailman.11930.1405611654.18130.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
Hello Everyone
I am very much new to python scripting and i am here for knowledge
exchange.
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
Any suggestion will be appreciated. Thanks
Back to top | Article view | comp.lang.python
csiph-web