-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataGenerator.py
49 lines (40 loc) · 913 Bytes
/
DataGenerator.py
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
49
import random
N = 10
train_samples = 1000
test_samples = 150
f = open("Train.txt", "w")
for i in xrange(train_samples):
a = []
sum = 0.0
count = 0
for j in xrange(N):
temp = random.random()
if temp <= 0.5:
a.append( random.randint(0,N) )
sum += a[-1]
count += 1
else:
a.append(0)
if count != 0:
for item in a:
print >> f, item,
print >> f, sum/count
f.close()
f = open("Test.txt", "w")
for i in xrange(test_samples):
a = []
sum = 0.0
count = 0
for j in xrange(N):
temp = random.random()
if temp <= 0.5:
a.append( random.randint(0,N) )
sum += a[-1]
count += 1
else:
a.append(0)
if count != 0:
for item in a:
print >> f, item,
print >> f, sum/count
f.close()