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

Revision 9372:aef193695ea9, 1.3 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, objectsOnEdges = 1)
10graph.objects = ["Age", "Gender", "Height", "Weight"]
11
12graph["Age", "Gender"] = "a string"
13# commented out: causes differences in regression tests between machines
14#graph["Age", "Height"] = orange
15graph["Gender", "Height"] = [1, 2, 3]
16print graph.get_edges()
17
18print graph[1, 2]
19print graph["Gender", "Height"]
20print graph["Age", "Gender"]
21print graph["Age", "Height"]
22
23graph.objects = {}
24graph.objects["Age"] = 0
25graph.objects["Gender"] = 1
26graph.objects["Height"] = 2
27
28print graph["Age", "Gender"]
29try:
30    print graph["Gender", "Height"]
31except:
32    print 'graph["Gender", "Height"] failed'
33
34print graph.get_neighbours("Age")
35graph.returnIndices = 1
36print graph.get_neighbours("Age")
37
38
39graph = Orange.network.GraphAsMatrix(5, 0, 3)
40print graph[4, 1]
41graph[4, 1, 1]=12
42print graph[4, 1, 1]
43print graph[4, 1]
44
45print graph.edge_exists(4, 1)
46print graph.edge_exists(4, 2)
47print graph.edge_exists(4, 1, 1)
48print graph.edge_exists(4, 1, 2)
49
50e = graph[4, 1]
51e[1]
52e[2]
53e[1] = None
54e[2] = 3
55print graph.edge_exists(4, 1, 1)
56print graph.edge_exists(4, 1, 2)
57print e
58graph[4, 1]=None
59print e
Note: See TracBrowser for help on using the repository browser.