# source:orange/Orange/testing/regression/tests_20/reference_exampletable1.py@9952:986e9cd806f4

Revision 9952:986e9cd806f4, 1.1 KB checked in by Miha Stajdohar <miha.stajdohar@…>, 2 years ago (diff)

Tests moved and renamed from orange 20.

Line
1# Description: Shows how to construct an orange.ExampleTable out of nothing
2# Category:    basic classes
3# Classes:     ExampleTable, Domain
4# Uses:
5# Referenced:  ExampleTable.htm
6
7import orange, random
8random.seed(0)
9
10card = [3, 3, 2, 3, 4, 2]
11values = ["1", "2", "3", "4"]
12
13attributes = [orange.EnumVariable(chr(97+i), values = values[:card[i]])
14              for i in range(6)]
15
16classattr = orange.EnumVariable("y", values = ["0", "1"])
17
18domain = orange.Domain(attributes + [classattr])
19
20data = orange.ExampleTable(domain)
21for i in range(5):
22    ex = [random.randint(0, c-1) for c in card]
23    ex.append(ex[0]==ex[1] or ex[4]==0)
24    data.append(ex)
25for ex in data:
26    print ex
27
28loe = [
29    ["3", "1", "1", "2", "1", "1",  "1"],
30    ["3", "1", "1", "2", "2", "1",  "0"],
31    ["3", "3", "1", "2", "2", "1",  "1"]]
32
33d2 = orange.ExampleTable(domain, loe)
34d2[0] = ["1", "1", 1, "1", "1", "1", "1"]
35
36import numpy
37d = orange.Domain([orange.FloatVariable('a%i'%x) for x in range(5)])
38a = numpy.array([[1, 2, 3, 4, 5], [5, 4, 3, 2, 1]])
39t = orange.ExampleTable(a)
40print len(t)
41print t[0]
42print t[1]
Note: See TracBrowser for help on using the repository browser.