Bonjour, je veux compter la fréquence d'un graphe en utilisant networkx, les graphes (transactions) sont sous forme d'un fichier : http://pastebin.com/E2P3H8GT
le problème ce trouve apparemment dans cette ligne : G_list.count(G_list[60])
mais je ne comprends pas pourquoi ! comment régler ce problème svp!
voila le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
48 import networkx as nx # read graphs from file. def readGraphFile(graphFile): G_list = [] appearance = [] #store the appearance of the frequent pattern fp = open(graphFile, "r+") lines = [line for line in fp.read().splitlines() if line] for line in lines: data = line.split() if data[0] == 't': if (len(data) < 3): print 'Graph header line error...' else: g = nx.Graph() G_list.append(g) elif data[0] == 'v': data = line.split() if (len(data) < 3): print 'Node data line error...' else: g.add_node(data[1], attrib = data[2]) #as node graph transaction format is single value, use attrib as a common noun for all attrib elif data[0] == 'e': if (len(data) < 4): print 'Edge data line error...' else: g.add_edge(data[1], data[2]) else: print line print '!!! Invalid graph data line...!!!' print 'Finished reading in graph...' print 'Total graph in list: ', len(G_list) ########Problem it count frequence############### print "frequence of graph t # 60", G_list.count(G_list[60]) #programme pricipale def main(): readGraphFile("60.txt") if __name__ == '__main__': main()
Partager