# source:orange/docs/reference/rst/code/network-graph.py@9372:aef193695ea9

Revision 9372:aef193695ea9, 1.1 KB checked in by mitar, 2 years ago (diff)

Moved documentation to the separate directory.

Line
1# Description: Shows how to use graphs
2# Category:    general
3# Classes:     Graph
4# Uses:
5# Referenced:  graph.htm
6
7import Orange.network
8
9graph = Orange.network.GraphAsMatrix(4, 0)
10graph.objects = ["Age", "Gender", "Height", "Weight"]
11
12graph["Age", "Gender"] = 0.1
13graph["Age", "Height"] = 1.2
14graph["Gender", "Height"] = 0.3
15print graph.getEdges()
16
17print graph[1, 2]
18print graph["Gender", "Height"]
19
20graph.objects = {}
21graph.objects["Age"] = 0
22graph.objects["Gender"] = 1
23graph.objects["Height"] = 2
24
25print graph["Age", "Gender"]
26try:
27    print graph["Gender", "Height"]
28except:
29    print 'graph["Gender", "Height"] failed'
30
31print graph.getNeighbours("Age")
32graph.returnIndices = 1
33print graph.getNeighbours("Age")
34
35
36graph = Orange.network.GraphAsMatrix(5, 0, 3)
37print graph[4, 1]
38graph[4, 1, 1]=12
39print graph[4, 1, 1]
40print graph[4, 1]
41
42print graph.edgeExists(4, 1)
43print graph.edgeExists(4, 2)
44print graph.edgeExists(4, 1, 1)
45print graph.edgeExists(4, 1, 2)
46
47e = graph[4, 1]
48e[1]
49e[2]
50e[1] = None
51e[2] = 3
52print graph.edgeExists(4, 1, 1)
53print graph.edgeExists(4, 1, 2)
54print e
55graph[4, 1]=None
56print e
Note: See TracBrowser for help on using the repository browser.