Skip to content

Commit e57250c

Browse files
authored
Add files via upload
1 parent e97e8f9 commit e57250c

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

picross_dataset.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#picross dataset
2+
#copyright fiorezhang@sina.com
3+
4+
import numpy as np
5+
from picross_generator import generator as gen
6+
7+
def load_data(row, col, visible, num):
8+
x = np.zeros((num, row, col), dtype='int16')
9+
y = np.zeros((num, 2, row, col), dtype='int16')
10+
11+
for i in range(num):
12+
x[i], y[i, 0], y[i, 1] = gen(row, col, visible)
13+
14+
return x, y
15+

picross_generator.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#picross_generator
2+
#copyright: fiorezhang@sina.com
3+
4+
import numpy as np
5+
6+
#calculate continued '1' for a string
7+
def calculate(s):
8+
g = s.shape[0]
9+
p = np.zeros((g), dtype='int16')
10+
x, y = 0, 0#x: current position in return string, y: whether in '1' slice
11+
for i in range(g):
12+
if y == 0:#not in '1' slice
13+
if s[i] == 1:
14+
y = 1
15+
p[x] += 1
16+
else:#in '1' slice
17+
if s[i] == 1:
18+
p[x] +=1
19+
else:
20+
x += 1
21+
y = 0
22+
return p
23+
24+
#generate the matrix, and calculated continued '1' number for rows and columns
25+
def generator(row, col, intense):
26+
m = np.random.rand(row, col)
27+
m = np.where(m<intense, 1, 0)
28+
#print('Expect: ', intense, 'Actual: ', m.sum()/(row*col))
29+
#print(m)
30+
31+
n_r = np.zeros((row, col), dtype='int16')
32+
n_c = np.zeros((row, col), dtype='int16')
33+
34+
for i in range(row):
35+
n_r[i] = calculate(m[i])
36+
37+
for j in range(col):
38+
n_c[:,j] = calculate(m[:,j])
39+
40+
if (m.sum() != n_r.sum()) or (m.sum() != n_c.sum()):
41+
print('ERROR')
42+
43+
return m, n_r, n_c
44+
45+
#test functions
46+
'''
47+
x, y, z = generator(10, 10, 0.6)
48+
print(x)
49+
print(y)
50+
print(z)
51+
'''

0 commit comments

Comments
 (0)